15

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?

GordyII
  • 7,067
  • 16
  • 51
  • 69
  • That's not irony: the task scheduler *has* finished running the task. The task itself, or cscript, is what's stuffing up here. – paxdiablo Mar 20 '09 at 04:49
  • Can you post the code for Bob.vbs? – Patrick Cuff Mar 20 '09 at 09:49
  • Where are you trying to write too? Hopefully not any network drives which wouldn't be present for the administrator. Are you able to simply login as administrator and trying to run the script to see what errors you get? Are you depending on any path or other environment settings that wouldn't be present for the administrator? – Zoredache Mar 20 '09 at 06:16

13 Answers13

9

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.

Jared
  • 1,385
  • 11
  • 21
  • 3
    Setting the optional "start in" parameter allowed all my scripts to run properly on Windows 7 / 2008 R2 boxes. I've been banging my head on this one for a couple of days. Thank you! – MikeCov Jan 10 '12 at 03:36
  • Maybe related - I updated to Win10 Pro 21H2 and task scheduler for .vbs files started failing around that time. Setting the 'start in' gets things back on track. – DAG Jan 20 '23 at 12:38
7

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.

Patrick Cuff
  • 28,540
  • 12
  • 67
  • 94
6

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\

Arbor
  • 71
  • 1
  • 2
5

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.

Community
  • 1
  • 1
john
  • 51
  • 1
  • 1
1

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

General Tab - (Check) Run with highest privileges

guest
  • 11
  • 1
1

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

Richard Erickson
  • 2,568
  • 8
  • 26
  • 39
0

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.

Marko
  • 20,385
  • 13
  • 48
  • 64
kingkeamo
  • 274
  • 2
  • 6
0

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.

Dorina Dede
  • 171
  • 2
  • 5
0

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

kjsm
  • 1
  • 1
0

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.

Nate
  • 1
0

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.

Elias
  • 43
  • 6
0

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)

Chris
  • 39,719
  • 45
  • 189
  • 235
  • C# would be much better than mucking around with VBScript. I will have to suggest that to the boss :) – GordyII Mar 20 '09 at 04:50
  • The only problem I ever had was trying to run the VBS files directly (no parameters got passed through). That was solved by using cscript, which is obviously not the case here. Still, SysWOW64 interaction is what I'd be looking at. – paxdiablo Mar 20 '09 at 04:54
0

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.

Jay Riggs
  • 53,046
  • 9
  • 139
  • 151