Link to home
Start Free TrialLog in
Avatar of Brandon Garnett
Brandon Garnett

asked on

Run a batch file from Task Scheduler in 32-bit mode on a 64-bit server

Hello,

I am using Windows Server 2008 R2.

I have a batch file that calls 3 procedures; 2 are Stored Procedures in SQL SERVER and the last is a VBScript.

My VBScript HAS to run in 32-bit mode due to the providers and connections it has inside it.

If i run the batch file manually in %windir%\syswow64\cmd.exe, Everything works correctly and how it should.

If the batch file is run in %windir%\system32\cmd.exe , The 2 stored procedures will run but my vbscript Errors out due to the provider and connections.

I need this batch file to run from Task Scheduler which is my problem. How do i set up Task Scheduler to run the batch file in %windir%\syswow64\cmd.exe so that my vbscript will execute properly as well?

Any assistance is much appreciated
Avatar of ryan_johnston
ryan_johnston
Flag of United States of America image

When you specify the task action to Start a Program, specify the "Start In" location and have it run from Syswow64.
Avatar of Steven Carnahan
Create the scheduled task with this as the Action:  

C:\Windows\SysWOW64\cmd.exe /C path\to\batchfile.cmd
Probably setting the starting folder will not help.

You have several choices:
1. Run the task in 64bit mode, and only start the VBS part in 32bit. You'll do that by explicitely noting the 32bit path to cscript (or wscript) in your batch.
@echo off
REM SQL Stuff here
%WinDir%\SysWOW64\cscript //nologo ManAtWork.VBS

Open in new window


2. Start the batch with 32bit cmd.exe, as you did manually. The task's executable is %WinDir%\SysWOW64\cmd.exe, and the arguments are /c C:\PathToScript\Script.cmd

Both should work the same.
Avatar of Brandon Garnett
Brandon Garnett

ASKER

Thanks for the quick responses everybody. I tried everything everyone suggested and i still can't get it to work correctly. I'm obviously not a Task Scheduler wiz. Do you have any other suggestions? Thanks again
Hmm. It's is really easy if you know the basics. I can't see what should go wrong with our suggestions. What is the issue if you try? Is the VBS part still running in 64bit, or is the batch not running at all? Since you got it "working" as a task before, I assume you do not have issues with UNC (network) paths and specific accounts for the task.
The Account has all privileges it needs for the tasks being done by the batch File. Everything Runs in the batch file except for the VBScript. The VBScript throws an error because of the whole provider thing so the VBS is still running in 64bit
After reading the original question again I think that Qlemo's first option may be the proper resolution. It doesn't look like it really matters if the batch file is run in 32 vs 64 bit. It is the VBS code that is the issue?
Correct. I just need the VBS to run in 32bit, The rest of the batch can run in either 32 or 64bit
You could put some code in the VBS script.  Something like:

Set oFso = CreateObject("Scripting.FileSystemObject")
Set oWs = CreateObject("WScript.Shell")
If InStr(WScript.FullName, "C:\Windows\System32\") And oFso.FolderExists("C:\Windows\SysWow64") Then
    ' rebuild arguments?
    oWs.Run "C:\Windows\SysWow64\WScript.exe """ & WScript.ScriptFullName & """"
    WScript.Quit
End If

Open in new window

Recheck your task settings. You have done something wrong, I'm sure. If the batch runs when started manually in a 32bit shell, it has to if you follow http:#a39311006 (or my 2nd suggestion).
Settings are as follows:
Run whether user is logged on or not
Run with Highest Privileges
Configure For: Windows 7, Windows Server 2008 R2
Trigger is every 30 Minutes
Action: Start Program - C:\windows\syswow64\cmd.exe
            Add Arguments - /c C:\proj_mgmt_reports\TestBatch.bat
Conditions:
Start Task only if Computer is on AC Power
Stop Task if Computer Switched to Battery Power
Wake Computer to run task
Settings:
Allow Task to be run on demand
Stop task if it runs longer than 3 days
If running task does not end when requested, force it to stop
If task is already running, do not start a new instance
New discovery and (possibly) harder piece to the puzzle.

In my batch file that i am running i have the line:
c:\windows\syswow64\cscript.exe TestVBS1.VBS

I ran the batch file manually in the 64Bit cmd (C:\Windows\System32\cmd.exe) which would normally cause the error i was referring to. Since i have that line, the Batch file executes the VBScript without error causing everything to be smooth.

However when i put the batch file into Task Scheduler, It runs and says it completes successfully but when i check the Data that my VBScript is suppose to alter, nothing has changed like it should, telling me the VBScript is not running or something along the lines.

Any Ideas?
Try removing the c:\windows\syswow64 from in front of the cscript.exe in the batch file.
pony10us,

I tried what you suggested about removing the c:\windows\syswow64\ from in front of the cscript.exe.

After removing that piece, i ran the batch file manually in 64Bit cmd and it threw an error in the VBScript due to using the 64Bit Cscript.exe
It will error out if you run it in 64bit mode however since we have instructed you to run the cmd.exe in 32bit mode as a scheduled task then it should be unnecessary.  Try running the batch file in 32 bit mode and see if it functions properly.

Is the batch file and the vbs in the same folder?

Another question, are you referencing any mapped drives in your scripts?
Yes the batch file and the vbs are in the same folder

Running the batch file manually in 32bit cmd works correctly

I ran it in 32bit cmd in Task Scheduler and the vbs never ran.

I added a debug line in my batch file that outputted the error from the VBS.

It states that the File path to my database that my connection string goes to is invalid.

file path is "T:\path\file.mdb"

This is a valid file path/file however. and it runs correctly if done outside task scheduler. Any ideas to why running it in task scheduler would cause this error to show up but not otherwise?

T: is a mapped drive which resides on another server
ASKER CERTIFIED SOLUTION
Avatar of Steven Carnahan
Steven Carnahan
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
That was it. I changed the File path to the Network path and it worked exactly how it should.

Thank you very much for your help and for dealing with my lack of knowledge when it comes to Task Scheduler.
Your welcome.

Sometimes the journey is just as fun and informative as the destination.