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

Difference between wscript and cscript

In Windows, an executable is either a console application or a Windows application (or a SFU or Native application, but that doesn’t matter here). The kernel checks a flag in the executable to determine which. When starting using CreateProcess WinAPI function, if it is a console application, the kernel will create a console window for … 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

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

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

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

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