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, 16 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 Search this Thread
Search this Thread:

Advanced Search




Similar help and support threads
Thread Forum
Batch File: works under cmd-Windows , NOT under MS-DOS
I made these codes to backup files : set p=C:\Users\ for /f %%a in ('dir C:\Users\ /b') do ( if not "%%a"=="Public", ( set fileDest=C:\Backup-%%a_%date:~7,2%.%date:~4,2%.%date:~10,4%
Virtualization
Batch file only works in certain directory
I made a batch file that says this: @echo off cd C:\Users\John\Desktop rename ring.gif ring.jpeg The actual batch file is saved on my I:\ drive, not my C:\ drive. My I:\ drive is an internal HDD that is able to talk with my C:\ drive. When I execute the .bat file, it does nothing...
General Discussion
File Manager that works?
Hi All, I was wondering if anyone can recommend an alternative file management program to windows explorer that works with Windows 7. Ones I've tried include.. 1: xplorer2 - Shuts down whenever I try renaming files. Will usually rename the first couple and then shut down. 2: ...
Software
Install Win7 & keep my file works
Please help,I have win7 on 250 gb hardisk and do not work anymore,may be problem with MBR error. I want to install new instalation (not clean install) because i want to restore my old software back).How can I do that ??,Please help me with step by step tutorial to do this.Thanks for help.
Installation & Setup
Windows Task Scheduler stays active after it runned a batch file
Hi small question, My batch file runs quite well in windows task scheduler, but it stays active. How can I make sure Task Scheduler finishes this? I am closing VLC player with a command ending with --play-and-exit and then vlc:quit (to kill the processes in the task manager).
Performance & Maintenance
Microsoft Works File help!
I have a MS Works database I created years ago, and I have it saved on a flash drive. How do I permanently move the file to a folder in the library? thanks! BTW, I still can't open Pandora Radio...I am using Google Chrome as my browser.
Microsoft Office


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 15:14.

Twitter Facebook Google+



Windows 7 Forums

Seven Forums Android App Seven Forums IOS App