Task Scheduler claims succesful, but is not


  1. Posts : 7
    Windows 7 Pro 32/64 bit
       #1

    Task Scheduler claims succesful, but is not


    I have created a new task, placed it in the scheduler, it runs on schedule, but I get no output.
    If I double click the task it works.

    My task is this: c:\users\fred\desktop\tr.bat
    ****************** @echo off
    echo. >> tracelog.txt
    echo --------------------------------------------------------- >> tracelog.txt
    echo Date: %date% Time: %time% >> tracelog.txt
    echo --------------------------------------------------------- >> tracelog.txt
    echo on
    tracert -4 207.118.111.181 >> tracelog.txt
    tracert -4 lax.testmy.net >> tracelog.txt
    rem tracert -4 sf.testmy.net >> tracelog.txt
    exit
    ****************

    Output when started manually:
    ***********************
    ---------------------------------------------------------
    Date: Sun 04/23/2017 Time: 10:11:06.66
    ---------------------------------------------------------

    Tracing route to 207-118-111-181.dyn.centurytel.net [207.118.111.181]
    over a maximum of 30 hops:

    1 <1 ms <1 ms <1 ms modem.Home [192.168.0.1]
    2 24 ms 23 ms 24 ms rb2-bras-sea.core.centurylink.net [63.231.10.152]
    3 76 ms 76 ms 75 ms 207-118-111-181.dyn.centurytel.net [207.118.111.181]

    Trace complete.

    Tracing route to lax.testmy.net [172.98.72.95]
    over a maximum of 30 hops:

    1 <1 ms <1 ms <1 ms modem.Home [192.168.0.1]
    2 24 ms 23 ms 27 ms rb2-bras-sea.core.centurylink.net [63.231.10.152]
    3 24 ms 24 ms 24 ms tukw-agw1.inet.qwest.net [71.217.187.9]
    4 23 ms 24 ms 24 ms sea-brdr-02.inet.qwest.net [67.14.41.190]
    5 24 ms 25 ms 24 ms be209.ccr21.sea02.atlas.cogentco.com [154.54.11.1]
    6 25 ms 28 ms 25 ms be2084.ccr22.sea01.atlas.cogentco.com [154.54.0.253]
    7 44 ms 43 ms 43 ms be2077.ccr22.sfo01.atlas.cogentco.com [154.54.0.241]
    8 44 ms 43 ms 44 ms be3179.ccr22.sjc01.atlas.cogentco.com [154.54.43.150]
    9 53 ms 53 ms 52 ms be3177.ccr22.lax01.atlas.cogentco.com [154.54.40.145]
    10 53 ms 55 ms 54 ms be2020.rcr22.lax04.atlas.cogentco.com [154.54.7.186]
    11 52 ms 54 ms 54 ms te0-0-1-3.agr12.lax04.atlas.cogentco.com [154.24.35.18]
    12 54 ms 53 ms 53 ms te0-0-2-0.nr11.b002695-2.lax04.atlas.cogentco.com [154.24.29.94]
    13 52 ms 53 ms 53 ms as46562.demarc.cogentco.com [38.88.196.166]
    14 54 ms 53 ms 53 ms vl51.dist-aa.lax01.as46562.net [104.200.152.57]
    15 52 ms 53 ms 53 ms lax.testmy.net [172.98.72.95]

    Trace complete.
    **************************
    A query of the task scheduler using schtasks (last screen shot) shows it is running.

    Anybody have a clue?

    Thanks for your time, Fred
    Attached Thumbnails Attached Thumbnails Task Scheduler claims succesful, but is not-ts-1.jpg   Task Scheduler claims succesful, but is not-ts-2.jpg   Task Scheduler claims succesful, but is not-ts-3.jpg   Task Scheduler claims succesful, but is not-ts-4.jpg   Task Scheduler claims succesful, but is not-ts-5.jpg  

    Task Scheduler claims succesful, but is not-ts-6.jpg   Task Scheduler claims succesful, but is not-ts7.jpg   Task Scheduler claims succesful, but is not-prompt.jpg  
      My Computer


  2. Posts : 3,783
    win 8 32 bit
       #2

    Why give it a .Bat extension that's old MS-DOS running command.com give it a . CMD extension. The problem will be on the user you have set and file location of desktop as that has permission set. Copy file outside user folder if that doesn't work change user run as system if you can
      My Computer


  3. Posts : 7
    Windows 7 Pro 32/64 bit
    Thread Starter
       #3

    samuria said:
    Why give it a .Bat extension that's old MS-DOS running command.com give it a . CMD extension.
    The only difference between these two are the errorlevel setting and I am no checking for that.


    samuria said:
    The problem will be on the user you have set and file location of desktop as that has permission set. Copy file outside user folder if that doesn't work change user run as system if you can
    Sorry don't understand that at all.
    But the scheduler claims it completed successfully, so why would any of it matter.
      My Computer


  4. Posts : 2,465
    Windows 7 Ultimate x64
       #4

    Task scheduler result actually only reports the errorlevel of the program it invokes, but it doesn't knows what it actually does or if it really succeeded. So for correctly reporting success/failure, you must return the proper errorlevel from the bat file.

    The script itself also contains two bugs.
    You're redirecting all output to "tracelog.txt". That implies that the file will be created in the current directory, but the bat file does't sets it, so the file will be created in whatever folder task scheduler will decide to run it by default (it isn't guaranteed to be the bat file folder if you don't set the "start in" option). Specify the full path in the redirection command or issue a CD command before.
    A second problem is that you're not checking errorlevel after the tracert commands. If either fails, the script will continue unmolested, overwriting the result with the next call. In practice what task scheduler will actually report will be the result of the last command, whose errorlevel will remain as the end result of the bat file. You should check errorlevel after each command and exit immediately with it so that the task scheduler properly reports failure when it happens.
      My Computer


  5. Posts : 7
    Windows 7 Pro 32/64 bit
    Thread Starter
       #5

    As per Alejandro85 I corrected the "errors" with this script:

    ********
    rem @echo off

    chdir c:\users\fred\desktop

    echo. >> tracelog.txt

    echo --------------------------------------------------------- >> tracelog.txt

    echo Date: %date% Time: %time% >> tracelog.txt

    echo --------------------------------------------------------- >> tracelog.txt

    echo on
    tracert -4 207.118.111.181 >> tracelog.txt
    if errorlevel 1 goto errorexit1

    tracert -4 lax.testmy.net >> tracelog.txt
    if errorlevel 1 goto errorexit2
    exit

    :errorexit1
    echo first tracert broken
    exit

    :errorexit2
    echo second tracert broken
    exit
    *****************

    But when trying to create the task I was hit with the attached error message at the very end since mine is not a "Basic Task".

    I do not use passwords, so that might be why it is failing to output anything. Anybody concur?

    As usual MS has hamstrung the program.

    Thanks, Fred
    Attached Thumbnails Attached Thumbnails Task Scheduler claims succesful, but is not-password-error.jpg  
      My Computer


  6. Posts : 3,783
    win 8 32 bit
       #6

    Did you run from a folder outside users restricted folder change the user to a group like user or admin group as per post 2
      My Computer


  7. Posts : 7
    Windows 7 Pro 32/64 bit
    Thread Starter
       #7

    Just realized I should use a "Pause" on my error exits to keep the window open.
      My Computer


  8. Posts : 7
    Windows 7 Pro 32/64 bit
    Thread Starter
       #8

    samuria said:
    Did you run from a folder outside users restricted folder change the user to a group like user or admin group as per post 2
    Please go back and read Post #5, I think no password is my problem.

    I am the only user, I am an administrator, I am running from c:\users\fred\desktop.

    Thanks, Fred
      My Computer


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

    FredY42, yes, you must give your account a password, and the credentials you specify must be of user “fred” if you’re going to write to “c:\users\fred\desktop”. Along with all of Alejandro85’s suggestions and tips, you should be good after that.


    samuria said:
    Why give it a .Bat extension that's old MS-DOS running command.com give it a . CMD extension.
    Samuria, you’ve been consistently making this suggestion for a while now and I encourage you to stop. No file extension has been associated with command.com since Vista. The .bat and .cmd extensions are both associated with cmd.exe, but there are still minor differences in the way scripts behave between the two. Changing an extension from .bat to .cmd can be a breaking change.
      My Computer


  10. Posts : 7
    Windows 7 Pro 32/64 bit
    Thread Starter
       #10

    Now I understand


    MS in their infinite stupidity demands a password if you want to schedule a task easily.

    Two work a rounds:
    1. Create 24 Basic Tasks, that don't require a password. Took time, but that is what I did, it works.
    2. Didn't find this till I was done:
    Using Windows Task Scheduler with blank password
    http://web.synametrics.com/syncrifytaskwopwd.htm
    Didn't try it either.

    It is understood and solved.
    Thanks everybody
    Last edited by FredY42; 27 Apr 2017 at 21:21. Reason: added thanks
      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 08:38.
Find Us