Showing posts with label api script. Show all posts
Showing posts with label api script. Show all posts

Monday, November 14, 2011

HowTo: Pretend you are working (While Text Browsing)

Commandline Web Browser (Just like lynx) using VbScript and IE API.

About the code: The code below will use the Internet Explorer API to load the top 20 stories from google news and choosing one of the article will load the document html of the target URL for you to be able to read news from your DOS command line. Best way to look like you are still working on a code while actually reading news without opening any web browsers :p

Requirements: IE 6++

Code Snippet:

Sub Loadnews()
Dim arrTestArray()
Dim urlSelect
intSize = 0
Dim rInterval:rInterval=60
Dim sTime:sTime = Now
Set ie = CreateObject("InternetExplorer.Application")
with ie
.visible = 0
.navigate "http://news.google.com/"
WScript.StdOut.Write vbcrlf & vbtab & "Loading Top Stories for @ " & Now
while .busy
WScript.StdOut.Write "."
WScript.Sleep 1000
wend
WScript.Echo vbcrlf & vbtab & "elapsed : " & datediff("s",sTime,Now) & " secs"
WScript.Echo vbtab & "next refresh: " & dateadd("s",rInterval,Now) & " secs" & vbcrlf
dim ctr:ctr=1
Set newsTitle = .Document.getElementsByTagName("a")
For each xTag in newsTitle
If instr(xTag.InnerHTML,"titletext") >0 then
WScript.Echo vbcrlf & vbtab & ctr & ". " & xTag.InnerText & _
"..." & vbcrlf & vbTab & "[" & xTag & "]"
ctr = ctr + 1
ReDim Preserve arrTestArray(intSize)
arrTestArray(intSize) = xTag
intSize = intSize + 1
If ctr >20 Then Exit For
End If
Next
end with
ie.quit
Set ie = nothing
Dim sleepctr:sleepctr=1
WScript.StdOut.Write vbcrlf & vbtab & "Choose an article #: "

urlSelect = WScript.StdIn.ReadLine
Set ie = CreateObject("InternetExplorer.Application")
Dim tgt:tgt=arrTestArray(urlSelect-1)
with ie
.navigate tgt
WScript.StdOut.Write vbcrlf & vbtab & "Loading [URL]..." & arrTestArray(urlSelect-1)
while .busy
WScript.StdOut.Write "."
WScript.Sleep 1000
wend
WScript.Echo .Document.Body.InnerText
end with
WScript.StdOut.Write vbcrlf & vbtab & "Press any key to continue..."
jcontinue = WScript.StdIn.ReadLine

End Sub


Screen grab:



If at first you fail, call it version 1.0

Monday, July 09, 2007

Merlin the great!

Imagine how amazed your users will be when they login to the domain and Merlin greets them...

You can call Merlin using Agent Control and make do the moves while you perform you login scripts in the background...

You can load information about the logged on user either using ADSI scripts or just by reading on the environment variable table...

Take note of the length of the messages or actions you throw at Merlin, you might need to make use of the Sleep method, otherwise the sentences or the animation will overlap...

Code Snippet:


  1. strAgentName = "Merlin"
  2. strAgentPath = "Msagent\Chars\" & strAgentName & ".acs"
  3. Set objAgent = CreateObject("Agent.Control.2")
  4. objAgent.Connected = True
  5. objAgent.Characters.Load strAgentName, strAgentPath
  6. Set merlin_d_great = objAgent.Characters.Character(strAgentName)
  7. With merlin_d_great
  8. .Show
  9. Set objRequest = .MoveTo(500,400)
  10. Set objRequest = .Play("Announce")
  11. Set objRequest = .Play("Explain")
  12. Set objRequest = .Speak("Hi ")
  13. Set objRequest = .Play("Read")
  14. wscript.sleep 2000
  15. Set objRequest = .Speak("Today is " & Now() & "...")
  16. Set objRequest = .Play("ReadContinued")
  17. wscript.sleep 2000
  18. Set objRequest = .Speak("and the time is " & Time() & "...")
  19. wscript.sleep 2000
  20. Set objRequest = .Play("ReadReturn")
  21. wscript.sleep 2000
  22. Set objRequest = .MoveTo(750, 450)
  23. Set objRequest = .Play("Pleased")
  24. wscript.sleep 5000
  25. Set objRequest = .Speak("I will be back shortly...")
  26. wscript.sleep 5000
  27. Set objRequest = .Play("Wave")
  28. wscript.sleep 5000
  29. .Hide
  30. End With

Have a blast with Merlin, and oh... you can use other characters aswell...

If at first you fail, call it version 1.0

Tuesday, June 26, 2007

Kix Copy script with GUI (Kixtart UDF)

Another KIXtart UDF, well the title says it all...

Dependencies:
KiX 4.02 (or higher)
Shell32.dll version 4.71 or later. (Included with: Windows 2000, Windows NT 4.0 with Internet Explorer 4.0, Windows 98, Windows 95 with Internet Explorer 4.0.)

Usage:
GUICopy("source", "destination", "optional flag", "optional flag")
@ERROR " : " @SERROR ?

Optional Flags:
4 - Do not display a progress dialog box.
8 - Give the file being operated on a new name in a move, copy, or rename
operation if a file with the target name already exists.
16 - Respond with "Yes to All" for any dialog box that is displayed.
64 - Preserve undo information, if possible.
128 - Perform the operation on files only if a wildcard file name (*.*) is
specified.
256 - Display a progress dialog box but do not show the file names.
512 - Do not confirm the creation of a new directory if the operation requires
one to be created.
1024 - Do not display a user interface if an error occurs.
2048 - Version 4.71. Do not copy the security attributes of the file.
4096 - Only operate in the local directory. Don't operate recursively into
subdirectories.
8192 - Version 5.0. Do not copy connected files as a group. Only copy the
specified files.


Returns The exitcode of the command in the @ERROR macro.
@ERROR = 0 The operation completed successfully.
@ERROR = 2 The system cannot find the file specified. (Refers to Source file.)
@ERROR = 3 The system cannot find the path specified. (Bad destination path.)
@ERROR = 9 The storage control block address is invalid. (Most likely cancelled copy.)
@ERROR = 10 The environment is incorrect. (Incorrect Shell32.dll version.)
@ERROR = 87 The parameter is incorrect. (Use 0 or 1 to specify Copy or Move.)

Code Snippet:

  1. Function GUICopy($sSrc, $sDest, OPTIONAL $lFlags, OPTIONAL $bMove)
  2. Dim $sVer,$objShell,$objFldr
  3. If Not Exist($sSrc) Exit 2 Endif
  4. If Not Exist($sDest) Exit 3 Endif
  5. If @INWIN=1
  6. $sVer=GetFileVersion(%WINDIR%+"\System32\Shell32.dll","FileVersion")
  7. Else
  8. $sVer=GetFileVersion(%WINDIR%+"\System\Shell32.dll","FileVersion")
  9. Endif
  10. If $sVer<"4.71" Exit 10 Endif
  11. $objShell=CreateObject("Shell.Application")
  12. $objFldr=$objShell.NameSpace($sDest)
  13. If @ERROR<0 Exit VAL("&"+Right(DecToHex(@ERROR),4)) EndIf
  14. Select
  15. Case $bMove=1 $objFldr.MoveHere($sSrc,$lFlags)
  16. Case $bMove=0 $objFldr.CopyHere($sSrc,$lFlags)
  17. Case 1 Exit 87
  18. EndSelect
  19. If @ERROR<0 Exit VAL("&"+Right(DecToHex(@ERROR),4)) EndIf
  20. Exit @ERROR
  21. EndFunction

If at first you fail, call it version 1.0

Monday, June 11, 2007

Viral detection on multiple page loads

Aside from having too much page loads detected as being viral, too much query from a single point of origin is also detected as viral... now this is the time that when the search results will prompt you for message that this query format is detected as virus and will ask you to key in the confirmation code to confirm that it was a valid search query.

Anyway, since ie will just crash your machine when performing too much page load and queries, I have written another scriptlet that utilizes MSXML2.ServerXMLHTTP.4.0 instead, so no api calls are made to unreliable but wonderfully obedient ie.

Set xmlhttp = CreateObject("MSXML2.ServerXMLHTTP.4.0")

'::::: Set your proxy here, comment it if not required


xmlhttp.setProxy 2,"10.1.1.1:8080"

'::::: Open the url using http Get

xmlhttp.open "GET", purl, false

You may use the following as part of your query URL:

InURL:Index.Of?mp3 InText:Index.Of?mp3 InTitle:Index.Of?mp3 InURL:Top Keywords InText:Top Keywords InTitle:Top Keywords InURL:scripts InText:scripts InTitle:scripts InURL:niche InText:niche InTitle:niche InURL:adsense InText:adsense InTitle:adsense InURL:income InText:income InTitle:income InURL:3gp InText:3gp InTitle:3gp InURL:hotel InText:hotel InTitle:hotel InURL:travel InText:travel InTitle:travel InURL:medicine InText:medicine InTitle:medicine InURL:new InText:new InTitle:new InURL:best InText:best InTitle:best InURL:rare InText:rare InTitle:rare InURL:free InText:free InTitle:free InURL:finance InText:finance InTitle:finance InURL:movie InText:movie InTitle:movie InURL:download InText:download InTitle:download InURL:source InText:source InTitle:source InURL:game InText:game InTitle:game InURL:music InText:music InTitle:music InURL:audio InText:audio InTitle:audio InURL:film InText:film InTitle:film InURL:digital InText:digital InTitle:digital InURL:flight InText:flight InTitle:flight InURL:school


':::::: Make sure you define your Browser Agent or else queries will not be allowed and will prompt you for blocks of code that you might need to submit to rectify the malformed query.

xmlhttp.setRequestHeader "User-Agent","Microsoft Internet Explorer"


xmlhttp.send()


':::::: You can do anything with the search results, follow the links, blah
WScript.Echo xmlhttp.responseText

set xmlhttp = nothing


If at first you fail, call it version 1.0

Why Click it, If you can script it?

While 10,000 ecpm can earn you $0.40, one wonders how much it takes to actually earn...

A sequel to my previous post on my recent fascination on ecpm, page loads doesn't mean much if either the page loads are in millisecond and no links in the pages are clicked or the search option was utilized...

Adding an extra function allows the page loads to have a little extra sense as not only page loads will be peformed, but hey... even the search option is populated with a query string (maybe from an array, etc...)... and an added trick to perform the click to actually perform the query...

To fill up the input for the search utility:
.Document.All.tags("INPUT")("q").Value = searchKey

To Click the search button:
Set sButt = .Document.getElementsByTagName("INPUT")
For Each Butt in
sButt
If LCase(Butt.getAttribute("value")) = "search" Then
Butt.Click
Exit For
End If
Next

If this makes sense and actually is acceptable, why not click on all the links in the result page to add up to your ecpm queries...

Set xLinx = .Document.getElementsByTagName("a")
For Each Linx In xLinx
Linx.Click
Next

Note: Make sure that your site setting is to load the results in the same page, rather than popping up new windows... or else you will flood your screen with tons of ie windows... hahaha... (this, even if .visible=0)

A terminate process will help in getting rid of all the unwanted window popups:

Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colProcessList = objWMIService.ExecQuery _
("SELECT * FROM Win32_Process WHERE Name = 'Iexplore.exe'")
For Each objProcess in colProcessList
objProcess.Terminate()
Next

Note: Do this after each page finishes loading after the click.

A draw back is that all your cookies and such are tracked, hence after numerous reloads and queries it might be detected as a viral activity, solution... clear your tracks...

First, get you cache path from your registry:
CachePath = WshShell.RegRead("HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Internet Settings\Cache\Paths\Directory")

Then parse through the folders to delete all cache:
Set rootFolder = fso.GetFolder(CachePath)
Set subFolders = rootFolder.SubFolders
For Each folder in subFolders
fso.DeleteFolder(folder)
Next

You may reuse the same to delete the remaining files in the rootfolder. Just replace .SubFolders to .Files.

There you go...

As easy as it looks like and as cool as it may seem, this will not guarantee that you will actually earn anything based on pageloads and queries... ecpm is not as easily attainable although your site is now generating billions of pageloads\month...

And knowing how M$oft Internet Explorer sucks bigtime, you know that it will crash alot if you execute this like 10,000 times????

Anyway, I use Opera and Firefox 50/50... I only use IE to test my scripts to see how long it will take to crash it...

Good luck!

If your first attempt fails, call it version 1.0

Tuesday, June 05, 2007

1,000 eCPM can earn you only $0.01

Just a script that does nothing but loads a page repeatedly...
Hmmm... might be useful or not useful...
Can It be used to accumulate eCPM?

Totally up to you...

psURL = "Your desired url..."
psURL2 = "Second desired url..."
Dim x
Dim IE

x=0
Set IE = CreateObject("InternetExplorer.Application")

With IE
.menubar=0

.toolbar=0
.statusBar=0
.navigate psURL
.visible=0
.resizable=1
Do while .busy
Loop

Do While x < "desired amout of page loads"
WScript.Echo Now & " - Count Load: " & x
.navigate2 psURL
WScript.Echo Now & " - Loaded: " & psURL
Do while .busy
Loop

x =x + 1
WScript.Echo Now & " - 15sec sleep..."
WScript.Sleep(15000)
.navigate2 psURL2
WScript.Echo Now & " - Loaded: " & psURL2
Loop
End With




Thursday, May 24, 2007

SMTP using .NET Classes (Powershell)

A great Powershell code that you can use as a template for SMTP mail with authentication.

Easily extendible for Web development.


Scriptlet:
###############################################
$mail = new-object System.Net.Mail.MailMessage

#set sender email address
$mail.From = new-object System.Net.Mail.MailAddress("mymail@mydomain.com");

#set the recepient email address
$mail.To.Add("touser@domain.com");

#set the email subject
$mail.Subject = "";

#set the content

$mail.Body = "";

#send the message
$smtp = new-object System.Net.Mail.SmtpClient("mydomain.com");

#set the username and password properites on the SmtpClient for authentication
$smtp.Credentials = new-object System.Net.NetworkCredential("username", "password");

#send it
$smtp.Send(mail);


#Voila!
###############################################


Monday, May 21, 2007

Powershell Lynx Project

Those were the days of Lynx when you used to browse the web as text thru the console...

My previous blogs were about scripting with Yahoo api search services. Well, since blogging at work is not really encouraged, I have decided to create my powershell version of Lynx. Since I'm scripting most of the time due to adHoc script requests, my boss won't even realize that I'm actually blogging... hehehe...

For starters, a scriptlet that navigates IE:

$ie = New-Object -com InternetExplorer.Application
$ie.Visible=$true
$ie.MenuBar=$false
$ie.ToolBar=$false
$ie.StatusBar=$false
$ie.Navigate("http://26thgstreet.blogspot.com")


Visibility of IE can be set to false later after I finalized the function to get the HTMLDocument.Innertext and write it to the console.

I will aso have to create a function to accept console arguments to be posted to the HTMLDocument so that I can update my blogs...

Stay tuned for the script updates.



Free PowerShell Book

My msdn feeds shed some light on my powershell addiction after receiving the good news.

It's finally out, thanks to Frank Koch.


The subtitle is "An introduction to scripting technologies for people with no real background knowledge". Read more.

Get it here.


Friday, May 18, 2007

Yahoo Search Script

Something to share...

Using MsXML.DOMDocument, you will be able to query Yahoo! API (
http://api.search.yahoo.com/WebSearchService/V1/webSearch?) .

Query Parameters used:


''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Yahoo Search Script
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Const APP_ID = "insert your app ID"

'Grab the incoming search query or ask for one
If WScript.Arguments.Length = 0 Then
strQuery = InputBox("Enter a search Term")
Else
strQuery = WScript.Arguments(0)
End If

'Construct a Yahoo! Search Query
strLanguage = "en"
strReqURL = "http://api.search.yahoo.com/" & _
"WebSearchService/V1/webSearch?" & _
"appid=" & APP_ID & _
"&query=" & strQuery & _
"&language=" & strLanguage

'Start the XML Parser
Set MSXML = CreateObject("MSXML.DOMDocument")

'Set the XML Parser options
MSXML.Async = False

'Make the Request
strResponse = MSXML.Load(strReqURL)

'Make sure the request loaded
If (strResponse) Then

'Load the results
Set Results = MSXML.SelectNodes("//Result")

'Loop through the results
For x = 0 to Results.length - 1
strTitle = Results(x).SelectSingleNode("Title").text
strSummary = Results(x).SelectSingleNode("Summary").text
strURL = Results(x).SelectSingleNode("Url").text
strOut = (x + 1) & ". " & _
strTitle & vbCrLf & _
strSummary & vbCrLf & _
strURL & vbCrLf & vbCrLf
WScript.Echo strOut
Next

'Unload the results
Set Results = Nothing

End If

'Unload the XML Parser
Set MSXML = Nothing
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''