Windows 7 Forums
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

 
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 SpecsSystem Spec
.
19 Apr 2015   #2
Golden
Microsoft MVP

Windows 7 Ult. x64
 
 

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 SpecsSystem Spec
19 Apr 2015   #3
blockie

 

Here it is and thanks for the help.
Bill


Attached Files
File Type: bat DELIMAGE.BAT (41 Bytes, 21 views)
My System SpecsSystem Spec
.

21 Apr 2015   #4
Pyprohly

Windows 10, Windows 8.1 Pro, Windows 7 Professional, OS X El Capitan
 
 

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 SpecsSystem Spec
21 Apr 2015   #5
Golden
Microsoft MVP

Windows 7 Ult. x64
 
 

Thanks Pyphrophly. Sorry Blockie....I completely forgot about this one.
My System SpecsSystem Spec
22 Apr 2015   #6
blockie

 

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 SpecsSystem Spec
23 Apr 2015   #7
Pyprohly

Windows 10, Windows 8.1 Pro, Windows 7 Professional, OS X El Capitan
 
 

Quote   Quote: Originally Posted by blockie View Post
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 SpecsSystem Spec
24 Apr 2015   #8
blockie

 

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 SpecsSystem Spec
25 Apr 2015   #9
Pyprohly

Windows 10, Windows 8.1 Pro, Windows 7 Professional, OS X El Capitan
 
 

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 SpecsSystem Spec
26 Apr 2015   #10
blockie

 

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 SpecsSystem Spec
Reply

 Run works in bat file but NOT in scheduler




Thread Tools




Similar help and support threads
Thread Forum
Import Reg File: cmd works - Reg\Regedit w/bat file doesn't work?
This is embarrassing but I've spent so many hours on it I feel I have no choice. :o I'm not real keen with Win 7 yet and I've done this with earlier os's without this problem. Can't figure out why it's not working here, and I see many others having similar questions. OS = Win7 Pro 32 bit. ...
General Discussion
Task Scheduler deleting bat file and removing permissions for folder.
I have a simple bat file that launches firefox and runs an in-browser macro that logs me on. It's worked flawlessly, at 7am and 3pm every day. Suddenly today, Task Scheduler launches it and mid-bat file, deletes it. - I tried to copy paste the macro back in and rename it, it tells me I don't have...
General Discussion
Task Scheduler: Batch file stuck in 'running' status
I need to run a batch file using the System account when a user logs on. This is needed for Crashplan to see network drives, following the tip at The Crashplan Network Drive Workaround My batch file does the following: net use r: \\server\folder1 net use s: \\server\folder2 I have created...
Performance & Maintenance
Windows Task Scheduler Batch File
Hello: I have a Batch File, to move a file to a different folder, that I would like to run from Windows Task Scheduler on a windows server 2008 R2 . The batch file itself works, however running it from Windows Task Scheduler does not work. I am trying to move the file within the L drive. I...
General Discussion
Windows Task Scheduler Move File
Hello: Using windows task scheduler, how do I move a file to a different folder, there is a box Program/Script that can browse a file then there is a box Add arguments, where and how do I add the from and to file path Thanks much!
General Discussion


Our Sites

Site Links

About Us

Find Us

Windows 7 Forums is an independent web site and has not been authorized, sponsored, or otherwise approved by Microsoft Corporation. "Windows 7" and related materials are trademarks of Microsoft Corp.

Designer Media Ltd

All times are GMT -5. The time now is 14:25.
Twitter Facebook Google+