I have created a task in the Task Scheduler that is supposed to execute a .vbs file that I wrote. The problem is that each time the service runs, rather than actually executing the code, I am asked how I want to open the file. How can I stop this? Please do not suggest batch files; I cannot use them for this.
The command line is "C:\Program Files (x86)\Malwarebytes' Anti-Malware\Malwarebytes Task Scheduler Instructions\Batch Files\MalwarebytesScanAndUpdate.vbs"
.
The vbs file's code is...
Dim shell
Set shell = WScript.CreateObject ("WScript.Shell")
shell.Run "MalwarebytesUpdate.bat"
WScript.Sleep 300000 'Sleeps for 5 minutes.
shell.Run "MalwarebytesScan.bat"
Error
It sounds like you have wscript
configured as the default association for .vbs files instead of cscript
. You can check at a command prompt, using ftype
. On my plain Win7 64-bit Pro machine, it produces the following (which would indicate mine is configured to wscript.exe
as well):
C:\>ftype VBSFile
VBSFile="%SystemRoot%\System32\WScript.exe" "%1" %*
Change the Program/script entry, and add cscript.exe
to the beginning, so the full entry would read (all on one line, of course):
cscript.exe "C:\Program Files (x86)\Malwarebytes' Anti-Malware\Malwarebytes Task Scheduler Instructions\Batch Files\MalwarebytesScanAndUpdate.vbs"
If the Task Scheduler complains about cscript
, change it to
"%SystemRoot%\System32\cscript.exe" "C:\Program Files (x86)\Malwarebytes' Anti-Malware\Malwarebytes Task Scheduler Instructions\Batch Files\MalwarebytesScanAndUpdate.vbs"
If this doesn't work, cut the full pathname (again, including quotes), and paste it into the edit control labeled Add arguments (optional):.
You can also set cscript
to be your default script processor at the command-line (although I'd discourage it unless you're sure that's what you want to do):
C:\>cscript /H:Cscript
Note you'll have to do so at a command prompt opened as an administrator ("Start", type "Command", right click on "Command prompt" and choose "Run as Administrator" from the context menu), and execute the above from there. You'll get something like this as the output:
C:\Windows\system32>cscript /H:CScript
Microsoft (R) Windows Script Host Version 5.8
Copyright (C) Microsoft Corporation. All rights reserved.
The default script host is now set to "cscript.exe".
If you decide to undo it, repeat the above and use /H:WScript
instead.
C:\Windows\system32>cscript /H:WScript
Microsoft (R) Windows Script Host Version 5.8
Copyright (C) Microsoft Corporation. All rights reserved.
The default script host is now set to "wscript.exe".
Do they really include a single quote in their folder name? That's pretty nasty, IMO. :-)
I know this is really old, but I just had the same problem and solved it in the following way, whether or not it's the "correct" way, other's can judge.
I was trying to schedule a script C:\reminder.vbs to run at a specific time and had the same issue where I could run it by double clicking in explorer no worries, but when the task ran it asked what I wanted to open it with. I resolved the issue by changing the scheduled program/script from C:\reminder.vbs to wscript.exe "C:\reminder.vbs"
So it perhaps doesn't really explain why the initial problem was occurring, but it does make the script run correctly.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With