Wednesday, December 18, 2013

Batch script without a window

If you want to schedule a batch script on your client machine you might not want that pesky console window popping up or even showing in your task bar. Here's how to start a script without anything showing.
Set WinScriptHost = CreateObject("WScript.Shell")
WinScriptHost.Run Chr(34) & "x:/path/to/script.cmd" & Chr(34), 0
Set WinScriptHost = Nothing
The 0 is the magic number as it tells the script to hide the window.
The Chr(34) is quotes, if the path to your script contains spaces.

Save the code as a .vbs file and you should be able to double-click or schedule it like any other executable.