Saturday, September 6, 2014

My stupid mistakes about Windows Schtasks.exe

I do not know why. I used to create a lot of scheduled VBScript-ed tasks on Windows. But after quite a long time without doing the same operations, I get stucked when I try to do task scheduling on windows. I spent a lot of time just trying to find back how I did them years ago.

I am writing it down. I hope I won't have to waste time any more in the future for the same problem.

The key to run a VBScript by "Schtasks.exe" is at "/tr" field the command to run should be "C:\Windows\System32\CScript.exe //B" followed by the script itself.

I found my answer at the answer by Stephen Quan to this posted question.
You should use CScript.exe over WScript.exe so that commands like WScript.Echo will be output to console instead of Dialog Box. As you point out, the scheduled task should avoid MessageBox or any UI elements that could cause your script to block.
I recommend scheduling your script as follows:
C:\Windows\System32\CScript.exe //Nologo //B X:\PathToYourScript\YourScript.vbs
The options I choose for you are "Prevent logo display" and "Batch mode". Consult your online help by running CScript /? on a Command Prompt.

No comments:

Post a Comment