Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to start a VBS-script in Windows 7 task scheduler with Messagebox?

I am using Win7 x64 Professional, and try to run a VBS script using the Windows task scheduler. My problem is, that the script behaves totally different than a script started directly, even if I start it with high privilieges, and using the same user.

One thing that I have noticed is for example that it is not possible to output any messagebox on screen.

Under Windows XP, I remember there was an option called "allow interaction with desktop" that fixed a lot of these problems, but I cannot find these options on Win7.

I have also tried to run Wscript.exe, and pass the scriptfile as a commandlineoption, but this results in the script not being started at all, even though task scheduler says it was started correctly.

Can you please explain what is the best way to start a VBS in Win7 in order to have the same behaviour as the script would have if it was started directly in explorer?

like image 617
Erik Avatar asked Jan 19 '12 12:01

Erik


People also ask

How do I run a VBS script in Windows 7?

Click the Start button, and then click Run. In the Open field, type the full path of the script, and then click OK. You can also type WScript followed by the full name and path of the script you want to run.

Does Windows 7 support VBScript?

Because VBScript is part of the operating system, it will follow the same life cycle as the operating system with which it ships. Therefore, VBScript will at least be supported as long as Windows 7 and Windows Server 2008 R2 are. If it ships in Windows 8, it will be supported as long as that operating system.


1 Answers

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.

like image 74
Stephen Quan Avatar answered Sep 28 '22 10:09

Stephen Quan