Avatar of zorvek (Kevin Jones)
zorvek (Kevin Jones)Flag for United States of America

asked on 

Windows Task Scheduler Run bat File with a Path Parameter

Trying to set up a task in Windows Task Scheduler where a bat file is run and passed a path that contains spaces. I can get the bat file to run without the path parameter but not with the path parameter.

The action is "C:\Full\Path\To\Batch File.bat".

The parameter should be "C:Full\Path\To\Another File.txt" but, when I enter it, the bat file is not called and the Last Run Result is "(0x1)". Without the parameter, the bat file is run and the Last Run Result is "The operation completed successfully. (0x0)".

Kevin
Windows BatchWindows OS

Avatar of undefined
Last Comment
Bill Prew
Avatar of Bembi
Bembi
Flag of Germany image

So, the simplest solution would just be to remove the space from the file name.
What is the problem?
You may try to put it into double quotes "" ... "" or "'...'"
Avatar of zorvek (Kevin Jones)

ASKER

I stated the problem above.

"I can get the bat file to run without the path parameter but not with the path parameter."


Avatar of Bembi
Bembi
Flag of Germany image

Ok, now I understand....
So the first thing I would do is to echo out the parameter, first to see, if the if the batch is startet and second to get aware, what the batch receives. It is possibly that your batch produces an error due to the parameter, but hard to decide without seing the batch.
The missing backslash in your parameter is a type, right?    

Lets ask again, does it run without the spaces? 
Avatar of William Fulks
William Fulks
Flag of United States of America image

Often times with task scheduler it's just a folder permissions issues. Make sure the account running the command can access that folder.

Also, this may help -  https://stackoverflow.com/questions/4437701/run-a-batch-file-with-windows-task-scheduler
Avatar of NVIT
NVIT
Flag of United States of America image

Just for clarification please... Your Action:

Program/script: "C:\Full\Path\To\Batch File.bat".
Add arguments (optional): "C:\Full\Path\To\Another File.txt"

Open in new window


If above is correct, the issue is within the .bat file. If so, in the .bat file, enter this line at the top:
echo %1>"%temp%\debugbat.txt"

Open in new window


Run the task and examine the content of "%temp%\debugbat.txt"
Works for me
ASKER CERTIFIED SOLUTION
Avatar of zorvek (Kevin Jones)
zorvek (Kevin Jones)
Flag of United States of America image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of Bill Prew
Bill Prew

I decided to use wscript.exe:
wscript.exe "C:\Full\Path\To\Batch File.bat" "C:Full\Path\To\Another File.txt"
Not sure how this worked for you, WSCRIPT normally can't process a BAT extension file, and it certainly can't execute BAT commands if that's indeed what the BAT file holds.


»bp
Avatar of zorvek (Kevin Jones)

ASKER

Bill,

You are correct. And I really screwed up this question. And that explains one of the problems I was experiencing. I was switching between bat and vbs scripts. Oy vey!

So, is it correct to assume that bat files must be started with cmd or with no command at all, and non-bat scripts (vbs and ps1) must be run with wscript or cscript?

Kevin
Avatar of Bill Prew
Bill Prew

Yes, your last statement is basically true.  BAT files can be run as just theirfull path, or you can run them underneath a copy of cmd.exe, typically with the /C or /K options.

Windows Script Host (VBscript or JaveScript) files might be able to run by just specifying the path to the file (VBS or JS files) but more often you see them launched via WSCRIPT (window interface) or CSCRIPT (command line interface).

Powershell scripts typically would be launched from powershell.exe.


»bp
Windows OS
Windows OS

This topic area includes legacy versions of Windows prior to Windows 2000: Windows 3/3.1, Windows 95 and Windows 98, plus any other Windows-related versions including Windows Mobile.

129K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo