可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
I have a vbscript script that I runs fine when I am running it myself.
For some reason, when I run it under the task scheduler as an administration user, it runs, but doesn't even write to my log file. It shouldn't be permissions, as the
user I run it under is adminstrator.
Its a script calling 32 bit dlls on a Win2008 64 bit machine.
C:\windows\SysWOW64\cscript.exe Bob.vbs
I also set the local directory to where I run it from.
Ironically the task scheduler says that "successfully finishes" running the task.
Also, there are other scripts in the task scheduler running fine, its just this script.
Does anyone have a list of things that I can check?
回答1:
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.
回答2:
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.
回答3:
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.
回答4:
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\
回答5:
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
回答6:
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)
回答7:
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.
回答8:
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.
回答9:
For Windows 2008 you probably need to ensure that the task runs with administrative privileges.
General Tab - (Check) Run with highest privileges
回答10:
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.
回答11:
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
回答12:
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.
回答13:
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.