Run works in bat file but NOT in scheduler


  1. Posts : 605
    W7 Ultimate
       #1

    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 Computer


  2. Posts : 19,383
    Windows 10 Pro x64 ; Xubuntu x64
       #2

    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 Computer


  3. Posts : 605
    W7 Ultimate
    Thread Starter
       #3

    Here it is and thanks for the help.
    Bill
    Run works in bat file but NOT in scheduler Attached Files
      My Computer


  4. Posts : 721
    Windows 10, Windows 8.1 Pro, Windows 7 Professional, OS X El Capitan
       #4

    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 Computer


  5. Posts : 19,383
    Windows 10 Pro x64 ; Xubuntu x64
       #5

    Thanks Pyphrophly. Sorry Blockie....I completely forgot about this one.
      My Computer


  6. Posts : 605
    W7 Ultimate
    Thread Starter
       #6

    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 Computer


  7. Posts : 721
    Windows 10, Windows 8.1 Pro, Windows 7 Professional, OS X El Capitan
       #7

    blockie said:
    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 Computer


  8. Posts : 605
    W7 Ultimate
    Thread Starter
       #8

    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 Computer


  9. Posts : 721
    Windows 10, Windows 8.1 Pro, Windows 7 Professional, OS X El Capitan
       #9

    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 Computer


  10. Posts : 605
    W7 Ultimate
    Thread Starter
       #10

    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 Computer


 

  Related Discussions
Our Sites
Site Links
About 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 04:59.
Find Us