How to find the window Title of Active(foreground) window using Window Script Host

Short answer: You can’t. At least not without writing a COM wrapper for the relevant Windows API calls. Can’t you just use AppActivate and check the result? Set oShell = CreateObject(“WScript.Shell”) If oShell.AppActivate “Untitled – Notepad” Then oShell.SendKeys “Hello, world!” End If Long answer: To get the active window title, you need to call the … Read more

VBScript getting results from Shell

You will want to use the WshShell object’s Exec method instead of Run. Then simply read the command line’s output from the standard streams. Try this one: Const WshFinished = 1 Const WshFailed = 2 strCommand = “ping.exe 127.0.0.1” Set WshShell = CreateObject(“WScript.Shell”) Set WshShellExec = WshShell.Exec(strCommand) Select Case WshShellExec.Status Case WshFinished strOutput = WshShellExec.StdOut.ReadAll … Read more

Failproof Wait for IE to load

Try this one, it helped me to solve similar problem with IE once: Set oIE = CreateObject(“InternetExplorer.application”) oIE.Visible = True oIE.navigate (“http://technopedia.com”) Do While oIE.ReadyState = 4: WScript.Sleep 100: Loop Do While oIE.ReadyState <> 4: WScript.Sleep 100: Loop ‘ example ref to DOM MsgBox oIE.Document.GetElementsByTagName(“div”).Length UPD: Drilling down IE events I found that IE_DocumentComplete is … Read more

What is the ProgId or CLSID for IE9’s Javascript engine (code-named “Chakra”)

The CLSID for the Chakra Javascript engine installed with IE9 is {16d51579-a30b-4c8b-a276-0ff4dc41e755}. The InProcServer32 is %windir%\System32\jscript9.dll . There is no ProgId that I could find. That’s a bit odd; normally paired ProgId and CLSID entries refer to each other. For a given COM object, the ProgId key in the registry has a subkey called CLSID, … Read more

“rm -rf” equivalent for Windows?

RMDIR or RD if you are using the classic Command Prompt (cmd.exe): rd /s /q “path” RMDIR [/S] [/Q] [drive:]path RD [/S] [/Q] [drive:]path /S Removes all directories and files in the specified directory in addition to the directory itself. Used to remove a directory tree. /Q Quiet mode, do not ask if ok to … Read more

Can I pass an argument to a VBScript (vbs file launched with cscript)?

You can use WScript.Arguments to access the arguments passed to your script. Calling the script: cscript.exe test.vbs “C:\temp\” Inside your script: Set File = FSO.OpenTextFile(WScript.Arguments(0) &”\test.txt”, 2, True) Don’t forget to check if there actually has been an argument passed to your script. You can do so by checking the Count property: if WScript.Arguments.Count = … Read more

Detect when a web page is loaded without using sleep

Try conventional method: Set objIE = CreateObject(“InternetExplorer.Application”) objIE.Visible = True objIE.Navigate “https://www.yahoo.com/” Do While objIE.ReadyState <> 4 WScript.Sleep 10 Loop ‘ your code here ‘ … UPD: this one should check for errors: Set objIE = CreateObject(“InternetExplorer.Application”) objIE.Visible = True objIE.Navigate “https://www.yahoo.com/” On Error Resume Next Do If objIE.ReadyState = 4 Then If Err = … Read more

Windows XP or later Windows: How can I run a batch file in the background with no window displayed?

Here is a possible solution: From your first script, call your second script with the following line: wscript.exe invis.vbs run.bat %* Actually, you are calling a vbs script with: the [path]\name of your script all the other arguments needed by your script (%*) Then, invis.vbs will call your script with the Windows Script Host Run() … Read more

Base64 Encode String in VBScript

I was originally using some VBScript code from Antonin Foller: Base64 Encode VBS Function and Base64 Decode VBS Function. Searching Antonin’s site, I saw he had some code for quoted printable encoding, using the CDO.Message object, so I tried that. Finally, I ported the code mentioned in Mark’s answer to VBScript (also used some code … Read more

tech