My script won't run under the task scheduler. Why?

℡╲_俬逩灬. 提交于 2019-12-02 23:21:39

I had a similar problem running a scheduled task on my SVN server.

My script was writing to what I thought was the current working directory (the directory I specified for the task as the "Start in" folder). If I logged onto the server and ran the script it worked fine. When running as a scheduled job it wouldn't.

In my case, it looked like the scheduler re-assigned the working directory to be the directory specified in the TEMP environment variable for the user account used to run the job, not the directory I specified for the task (the "Start in" folder).

Check the TEMP folder for the account and see if your files are there.

I've had this problem with DOS batch files and VB scripts on Windows 2008 Server and Windows 7. In every case, once I set the "start in" folder for the scheduled task action, everything worked fine.

john

I had real problem with this (well a morning) and found this solution here:

In the windows task scheduler I had to click "change user or group" button and add "Administrators" group.

Hope it helps someone.

If you are running Win2008 64 bit machine: this (finally) worked for me on same server. Task scheduler runs a batch file (eg runvbs.bat) to call cscript with a 32bit version of the command line interpreter, like this:

@echo off
%windir%\syswow64\cmd.exe /C "c:\windows\system32\cscript.exe //B //nologo import_some_data.vbs"

Note the double quotes.

I used the Administrators group for permissions and Run with highest privileges.

Configure for: Windows® 7, Windows Server™ 2008 R2

In the Edit Action dialog I have:

Action: Start a program

Program/script: runvbs.bat

Start in: c:\inetpub\wwwroot\asp\importstuff\

Damion Willi

Solved this same issue. Script would fail when connecting to database then after fixing that it failed when creating Xls file. I created a bat file and added the below contents to it. this bat file will call my vb script and run it in 32 bit mode.

%windir%\SysWoW64\cmd.exe /C "c:\windows\system32\cscript.exe //B //nologo C:\ScheduledJobs\PrimeReconDev\myVBScript.vbs"

I set up the task schedule to execute my the bat file with the above contents and sect the executing user to Administrators. Do this by sing the "change user or group" option on the general tab. once done I was able to execute successfully no issues. i was initially executing as me and I am in the administrators group but it was still failing. Executing as built in administrators did the trick

I've had similar problems in the past with code not executing when scheduling vbs scripts - it can be problematic! Also curious to see if anyone can solve this. (by the way, we solved it by rewriting the code as a C# console application)

When I've had this problem it's usually because the program running on my task is erroring out, even though the return value of the completed task didn't report any problem.

You say it runs but doesn't write to your log -- is it possible it's crashing before it writes to your log?

If you haven't already, add error handling to your script and try to log any errors, or at least try to trace how far through the script it's getting.

kingkeamo

I had the same problem until I added the path where the bat job is stored into the Start in on the action tab.

Right click Task → Properties → Actions → Edit Start in (optional)

Just fill in the path to your bat job.

For Windows 2008 you probably need to ensure that the task runs with administrative privileges.

General Tab - (Check) Run with highest privileges

I had the same problem.

I fixed it by using relative path ("logs\log") instead of the absolute I was using before ("U:\workingDirectory\logs\log").

Aparently when you execute scripts via task scheduler you need to use relative paths.

I've had same issue. Used next string in Task -> Run field CMD /C "full path to my VBScript" like CMD /C c:\Test\MyScript.vbs

Looked all over to figure this out, but now that i got i will share.

Had scripts that ran fine on server 2003, trying to move to server 2012 and a portion of the script would not run.

Had to create a new task and on general tab select configure for "windows server 2003, Windows XP or Windows 2000. This option does not allow for 2003 if you use a basic task, you have to use new task.

Alternative Solution:

Run only when user is logged in

Make that selection inside of the task manager.


This is what fixed did it for me (on 3 Separate Computers - Win7 Pro, Win12 Server)

I hope it can help someone else.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!