Join Forum | Login | Today's Posts | Tutorials | Windows 10 Forum | Windows 8 Forum

 Welcome to Windows 7 Forums. Our forum is dedicated to helping you find support and solutions for any problems regarding your Windows 7 PC be it Dell, HP, Acer, Asus or a custom build. We also provide an extensive Windows 7 tutorial section that covers a wide range of tips and tricks.

# Windows 7: Run works in bat file but NOT in scheduler

 19 Apr 2015 #1 blockie W7 Ultimate 617 posts in Assisted Care facility, Calif Run works in bat file but NOT in scheduler I have a batch file that removes files from a folder on a periodic basis. I created a task in the scheduler to have it run on a daily basis. I'm sure that all the parameters are correct. When I leave it up to the scheduler it fails with a 0x2331 error. When I run the task from the batch file it runs OK. When I try to run it from the scheduler it won't run. I have checked the path to the batch file time and again. I know its OK. When I let the scheduler run normally it doesn't do the removal and returns an error of 0x2331. I have checked and re-checked all settings. Even compared to an unrelated task that does work. Any ideas? Bill My System Specs
 .
 19 Apr 2015 #2 Golden Windows 7 Ult. x64 19,353 posts South Australia A 0x2331 error usually means the program/command isn't recognised by the system. Please upload the .bat file here and I'll take a look at it for you. My System Specs
19 Apr 2015   #3
blockie

Here it is and thanks for the help.
Bill

Attached Files
 DELIMAGE.BAT (41 Bytes, 16 views)
My System Specs
 .
 21 Apr 2015 #4 Pyprohly Windows 10, Windows 8.1 Pro, Windows 7 Professional, OS X El Capitan 667 posts Sydney, NSW Hi Blockie, Specify the full path to this DELOLDER command. E.g. Code: "C:\Path\to\DELOLDER.exe" cd/D D:\images\*.mrimg /Keep:4 My System Specs
 21 Apr 2015 #5 Golden Windows 7 Ult. x64 19,353 posts South Australia Thanks Pyphrophly. Sorry Blockie....I completely forgot about this one. My System Specs
 22 Apr 2015 #6 blockie W7 Ultimate 617 posts in Assisted Care facility, Calif Both the batch file and Delolder.exe are in the same folder. I did it this way for convenience. the path is" c:\\Users\owner\desktop\myscripts\delolder.exe" Bill My System Specs
 23 Apr 2015 #7 Pyprohly Windows 10, Windows 8.1 Pro, Windows 7 Professional, OS X El Capitan 667 posts Sydney, NSW Quote: Originally Posted by blockie Both the batch file and Delolder.exe are in the same folder. There's your problem. You should understand that when you specify the DELOLDER command in your script, you are relying on the Current Directory to be C:\Users\owner\desktop\myscripts. One place CMD looks for commands is the current directory. When you execute a file through Explorer, the value of the current directory will be the path that your file resides in when you executed it. So DELOLDER.exe will reside in the current directory when you run your batch file through Explorer and your batch file is in the same folder as DELOLDER.exe. When Task Scheduler runs a 'task', the current directory is not the path that the executable or script is found in. Blockie, you've four options to fix your issue: A) Specify the full path of the command in your script, e.g., Code: "C:\Users\owner\Desktop\myscripts\DELOLDER.exe" cd/D D:\images\*.mrimg /Keep:4 B) Place the DELOLDER.exe application in a directory mentioned in the %Path% C) You many override default current directory Task Manager uses for your script by specifying a path for the "Start in (optional)" option in the Actions tab in Task Scheduler, D) If you only have a single command in your batch file then there is no need for a batch file at all. Simply let Task Scheduler run the DELOLDER command directly. My System Specs
 24 Apr 2015 #8 blockie W7 Ultimate 617 posts in Assisted Care facility, Calif I took option "D" of your post and already am doing "C". Let the scheduler run DELOLDER.EXE with appropriate switches. Now get a 0X5 completion code (access denied). I have checked the following, Run whether I am logged in or not If I double click DELOLDER.EXE there is a flash of the command prompt which tells me that it is doing something although no switches were used. So I am assuming that access is not denied doing this. My System Specs
 25 Apr 2015 #9 Pyprohly Windows 10, Windows 8.1 Pro, Windows 7 Professional, OS X El Capitan 667 posts Sydney, NSW To help troubleshoot the issue, place the command back into a batch file and append the pause command as the last line of the batch file. This will allow you to view the output of the command. My System Specs
 26 Apr 2015 #10 blockie W7 Ultimate 617 posts in Assisted Care facility, Calif Boy! Do I have egg on my face. Did as you recommended. Returned a file not found. The bat file with pause revealed that I was trying to delete file in folder "image". Used to have that folder but during a disk rearrangement I moved the files in question up one level and then removed folder "image", but failed to update the batch file. Works without error now. Thanks, Bill My System Specs