• Task Scheduler doing strange things…

    Home » Forums » AskWoody support » Windows » Windows 10 » Questions: Win10 » Task Scheduler doing strange things…

    Author
    Topic
    #2434831

    I am a long time reader of AskWoody newsletters. Now I need some help. I help a small non-profit with their tech work. All computers are running Windows 10 Pro version.

    A disk image is created every two weeks for each computer. The destination drive for the disk image is a USB connected external hard drive. Once the image file has been created it is later copied across the network to a network shared external drive on another PC. All this works well.

    I run a batch file on the source PC that does basically two things: 1. copies the file to its destination; 2. lists a directory of the source folder where the backup file was created and the list the directory for the destination folder where the file was copied to. The batch file output is appended to a log file. I do this to monitor that all files are current and monitor disk space.

    Since I primarily work remotely I have all the above batch file actions output to a log file which is then emailed to me.

    Here’s the rub. Everything works fine (been using this method for many years with no problems) except the line to list the network share directory does not produce the directory listing. The directory listing for the (local) attached USB drive is listed fine. And there’s a gotcha here…when I run the batch file from the folder where it resides (e.g., …username\documents\backup-stuff\) the network share directory (destination) is listed correctly. But I run this batch file in the Task Scheduler and when it’s completed there is no directory listing for the shared drive, only the local attached external drive.

    This is a new problem because I used to use a network share as the destination for the disk images but have changed to local attached USB external drives on each PC because of problems that have developed after a disk image software upgrade. What is Task Scheduler doing that causes the network share directory listing to not appear in the log file but it does show up when I just run the batch file?

     

    Viewing 8 reply threads
    Author
    Replies
    • #2434869

      Likely that the account that’s running the task scheduler job does not have permissions to view or access the network share.  Unless you specified a user account, it’s using the local machine system account by default.

      ~ Group "Weekend" ~

      • #2434872

        Thank you NetDef for the reply. I am running Task Scheduler from an admin account and also specified the admin account in the config for that task. I can view the network share in File Explorer and the batch file outputs the network share directory correctly when I run it manually.

        Al

         

    • #2434946

      Al,

      Have you specified the path value in the “Start in” section of the Task?

      StartIn

      That should fix the problem and run just as if you had done it manually. If that doesn’t work you might want to convert the batch to PowerShell where you have more control. I’d be glad to help.

      May the Forces of good computing be with you!

      RG

      PowerShell & VBA Rule!
      Computer Specs

      • #2434972

        I knew that would be the next question and I should have included that information. I do have the  path to the location of the batch file specified in the Start In box (C:\Users\username\Documents\backup_batch_file_location\).

        I thought about using PowerShell. I looked at the docs and some beginner help courses and my eyes started rolling around in my head. I’m sure it is a better option than the batch file but the learning curve is a bit steep to say the least. As I described earlier, the batch file does just a couple basic things…list directories; xcopy any newer files from one drive to the another and send all output to a text file.

        If it wasn’t for this hiccup in Task Scheduler I’d be a happy camper.

         

         

         

        • #2435054

          Did you put “quote marks” around the path in the Start in box? If so, remove them.

          I had a similar problem getting a “scheduled” batch file to work correctly and discovered Task Scheduler doesn’t work properly if there’s quotes around the path in Start in.

          Also, when using Task Scheduler to run a batch file, it gets run as a background task so mapped drives aren’t available using drive letters (drive letters are a “User Interface” only feature.)

          Background tasks must use the full UNC to access mapped drives (i.e. //server/share/*.* instead of r:/*.*)

    • #2435038

      Is there a reason you need to list the remote drive contents? Can you do it another way?

      cheers, Paul

    • #2435114

      If the above excellent suggestions above don’t help, there is one more odd detail I’ve run into in the past where network shares don’t behave in Batch File access under an admin account:

      Uncheck the option to “Run with highest privileges.”

      taskmanagerpermissions

      You may have to adjust permissions on other folders the admin/user account used by the batch file needs to access.

      ~ Group "Weekend" ~

    • #2435255

      Thank you all for your suggestions. I did not include quote marks in the Start In box and I disabled Run with highest privileges and I tried using the full UNC for the shared drive. All to no avail. Directory listing is still missing in the log file.

      Task Manager has a lot of little gotchas. Still no joy.

       

    • #2435273

      Any chance you could share your batch file?

      May the Forces of good computing be with you!

      RG

      PowerShell & VBA Rule!
      Computer Specs

      • #2435624

        Sure. I cut it down to the relevant lines:

        @echo off
        color 3F

        dir “O:Backup-04” > “C:\Users\UserName\Documents\Backup\BACKUP-Copy-image04.log”

        echo.

        dir “E:Backup-04” >> “C:\Users\\UserNameDocuments\Backup\BACKUP-Copy-image04.log”

        echo DONE >> “C:\Users\UserName\Documents\Backup\BACKUP-Copy-image04.log”

        exit

        The O: drive is the attached external USB drive.

        The E: drive is the network share.

        I ran this batch file manually from the local drive and both directories are listed properly. When I run the program from Task Scheduler only the O: drive is listed after it has completed.

        I’ve attached a couple screen grabs of the Task Scheduler windows.

        TaskScheduler1
        TaskScheduler2

        I appreciate all the useful suggestions. This has me flummoxed.

         

      • #2435631

        Huh…I see when I copied and pasted the batch file the AskWoody editor removed all the back slashes. I guess I should have escaped them.

        Anyway, here’s a screen grab of the file.

        batch-file

    • #2435637

      Instead of using a drive letter (E:), try naming the server and share directly. e.g.
      dir \\server\share\Backup-04

      cheers, Paul

      • #2435640

        As noted in my reply to alejr above I did use the full UNC with the same results.

    • #2435658

      Ok, just did a test on my own Win10 Pro and using the following modified version of your batch file.

      @echo off
      color 3F
      
      dir "F:\Test" > "C:\Temp\BACKUP-Copy-image04.log"
      
      echo.
      
      dir "A:\Test" >> "C:\Temp\BACKUP-Copy-image04.log"
      
      echo DONE >> "C:\Temp\BACKUP-Copy-image04.log"
      
      exit

      Drive F: is attached USB, drive A: is network mapped.

      Just like you, if run from a cmd prompt, the log file lists the contents of both drives but, if run from Task Scheduler, it only list the contents of drive F: (the USB drive)

      I changed

      "A:\Test" to "\\192.168.3.1\Test"

      (i.e. I replaced A: with its UNC value)

      Then it listed the contents of both drives when run from Task Scheduler.

      So, to get yours working you need to replace

      "E:"

      with it’s UNC value.

      To display the proper UNC for drive E:, run net use from a cmd prompt.

      The drive letter is under the “Local” column, the UNC value under the “Remote” column.

      1 user thanked author for this post.
    • #2435739

      Thank you, alejr. That was what was needed to resolve the problem. I did try to use the UNC path when you suggested it previously but I must have made a typo so it didn’t work. This time I copied the output from the net use command and pasted in place of the mapped drive letter path. Everything works correctly now. I get the network share directory listing in my log as I wanted.

      Thanks again to you and all the helpful AskWoody-ers that provided great suggestions.

    Viewing 8 reply threads
    Reply To: Reply #2435658 in Task Scheduler doing strange things…

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information:




    Cancel