Hide command prompt window when using Exec()

You’re always going to get a window flash with Exec(). You can use Run() instead to execute the command in a hidden window. But you can’t directly capture the command’s output with Run(). You’d have to redirect the output to a temporary file that your VBScript could then open, read, and delete. For example: With … Read more

Recursively access subfolder files inside a folder

This is actually a well-solved problem. Recursion means that you create a self-referencing function (a function that calls itself). In your case you’d make the function call itself for each subfolder of the current folder. TraverseFolders objFso.GetFolder(strPath) Function TraverseFolders(fldr) ‘ do stuff with the files in fldr here, or … For Each sf In fldr.SubFolders … Read more

VBScript — Using error handling

VBScript has no notion of throwing or catching exceptions, but the runtime provides a global Err object that contains the results of the last operation performed. You have to explicitly check whether the Err.Number property is non-zero after each operation. On Error Resume Next DoStep1 If Err.Number <> 0 Then WScript.Echo “Error in DoStep1: ” … Read more

About using Double quotes in Vbscript

In VBScript, string literals are surrounded by double quotes (“). This is what your first example shows: Msgbox “This is myName” ‘ This works fine However, if you want to include a double quote character inside of your string literal, you’ve got a problem, because VBScript is going to interpret the second double quote character … Read more