Calling cscript.exe and passing a vbscript to call

vbscriptwindows-server-2008-r2

I have scheduled a task in windows server 2008R2 ..I want to run a VBScript so when I setup the task I call the cscript at C:\Windows\System32\cscript.exe and in the arguments section I am passing //nologo //B d:\main\programs\copy.vbs /targets:contents but it is not executing my script ..If I call my script directly in the start program section it works fine but it's not working if I call CSrcipt and pass in arguments the status changes to queued but nothing happens after that..Can someone tell me what I am doing wrong here.

Also another question I have is that can we run 2 programs one after another in one task like when one script is finished I would like to start another script .

Thanks

Best Answer

Put this line at the top of your script and try again:

CreateObject("WScript.Shell").LogEvent 4, "Script running"

Unless you get an Information event with source WSH and event-ID 4, your script isn't running at all. Check the eventlog and the task's History tab for clues as to why that is. Also check the permissions of the script. Is the runas account of the task able to access/run the file? You can check that by starting a CMD instance as that user

runas /user:DOM\USER cmd

and then trying to run the script in that CMD instance.

Also double-check the task settings. As which user is it configured to run? With the user logged on or not logged on? Is "Run with highest privileges" enabled (in case UAC is enabled on your server)?

If the script does produce the abovementioned event that means it's running in principle, but something is going wrong in the process. You need to debug your script.

Related Topic