No announcement yet.

batch file wont work using scheduled task

  • Filter
  • Time
  • Show
Clear All
new posts

  • batch file wont work using scheduled task

    Please help, this is my batch file that i have been working on. It works when i run it straight but when i run it with the scheduled task. it runs for about a second and thats it. i have researched it but cant seem to solve them problem. please help.

    Moderator edit: added [code]-tags around the code
    @echo off
    echo Backup PST and Fav
    @For /F "tokens=1 delims=/ " %%A in ('Date /t') do @( 
    Set Today=%%A)
    REM Set DayForBackUp=Mon
    REM if not %Today% == %DayForBackUp% goto error
    REM Xcopy /E \\\Bridge-ts\"Documents and Settings and users"\micah\favorites\*.* f:\"bridge files"\staff\micah\Backups\ /Y 
    Xcopy /E t:\micah\favorites\*.* f:\"bridge files"\staff\micah\Backups\ /Y
    Xcopy /E t:\chris\favorites\*.* f:\"bridge files"\staff\chris\Backups\ /Y
    Xcopy /E t:\john\favorites\*.* f:\"bridge files"\staff\john\Backups\ /Y
    Xcopy /E t:\justin\favorites\*.* f:\"bridge files"\staff\justin\Backups\ /Y
    Xcopy /E t:\nicole\favorites\*.* f:\"bridge files"\staff\nicole\Backups\ /Y
    Xcopy /E t:\paul\favorites\*.* f:\"bridge files"\staff\paul\Backups\ /Y
    Xcopy /E t:\kathy\favorites\*.* f:\"bridge files"\staff\kathy\Backups\ /Y
    Xcopy /E t:\brian \favorites\*.* f:\"bridge files"\staff\brian \Backups\ /Y
    echo Backing up Favorites Complete.
    echo Please Wait while .PST file is backed up. This could take several minutes.
    copy t:\micah\"Local Settings"\"Application Data"\microsoft\Outlook\outlook.pst f:\"bridge files"\staff\micah\Backups\ /y
    copy t:\chris\"Local Settings"\"Application Data"\microsoft\Outlook\outlook.pst f:\"bridge files"\staff\chris\Backups\ /y
    copy t:\john\"Local Settings"\"Application Data"\microsoft\Outlook\outlook.pst f:\"bridge files"\staff\john\Backups\ /y
    copy t:\justin\"Local Settings"\"Application Data"\microsoft\Outlook\outlook.pst f:\"bridge files"\staff\justin\Backups\ /y
    copy t:\nicole\"Local Settings"\"Application Data"\microsoft\Outlook\outlook.pst f:\"bridge files"\staff\nicole\Backups\ /y
    copy t:\paul\"Local Settings"\"Application Data"\microsoft\Outlook\outlook.pst f:\"bridge files"\staff\paul\Backups\ /y
    copy t:\kathy\"Local Settings"\"Application Data"\microsoft\Outlook\outlook.pst f:\"bridge files"\staff\kathy\Backups\ /y 
    copy t:\brian \"Local Settings"\"Application Data"\microsoft\Outlook\outlook.pst f:\"bridge files"\staff\brian \Backups\ /y
    REM if not exist Outlook.pst goto error1
    echo Backing up PST file Complete.
    echo Location: t:\micah\"Local Settings"\"Application Data"\microsoft\Outlook
    goto datetime
    echo !! ERROR !! Did not find PST file.
    goto datetime 
    echo !! ERROR !! %Today% is not the configured backup day.
    goto datetime
    date /t
    time /t
    goto end
    Last edited by Rems; 4th December 2008, 10:40.

  • #2
    Re: batch file wont work using scheduled task

    If interactive mode works but sceduled won't, maybe you are running the task without appropriate rights. Launch a cmd shell as the user account you use for the scheduled task and look for errors. If this wont' help, insert some debugging statements into the script. Like:
    echo xcopy favourites started >> c:\temp\batchdebug.log
    echo xcopy favourites ended >> c:\temp\batchdebug.log
    This will allow you to determine on which part the script hangs.



    • #3
      Re: batch file wont work using scheduled task

      elijah, I have to give you a second warning!

      First you Hijacked a threah, I splitted your post to a new thread. Now your posting the exact question again, that makes it a Double post.

      READ the forum rules before posting

      I have closed the other thead, and made a link to this thread.

      moderator scripting forum

      Oh, can you wrap your code between [code]-tags the next time, that makes it better readable and better to copy. /thank you

      This posting is provided "AS IS" with no warranties, and confers no rights.


      ** Remember to give credit where credit's due **
      and leave Reputation Points for meaningful posts


      • #4
        Re: batch file wont work using scheduled task

        vonPryz is right,
        also read this post
        Does the 'runas account' have sufficient share and ntfs rights at the destination to write and delete files and add folders? and, is that account allowed to connect to the remote computer by the policy set on the remote computer?

        to capture messages during running of the batch, add these lines at the top of your batch
        @echo off
        Setlocal & Set "lastresults=c:\testscheduledtask"
        If /i Not exist "%lastresults%" MD "%lastresults%"
        > "%lastresults%\output.txt" 2>&1 (
        call :MyBatch ) & endlocal & goto:eof
        <your code comes here>
        Are the drives t: and f: mapped drives? then rather use the UNC-paths, or use "PushD" to create temporary mappings during running of the batch.


        This posting is provided "AS IS" with no warranties, and confers no rights.


        ** Remember to give credit where credit's due **
        and leave Reputation Points for meaningful posts