Announcement

Collapse
No announcement yet.

windows scheduler cannot run bat file

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • windows scheduler cannot run bat file

    I put the lines below in bat file. It run fine when click on it.
    But when I run it with Scheduled Tasks, the status is Could not start.
    Last result 0x0. Why this batch file cannot run from Scheduler?
    Have to mention I copy from 2000 server to 2003.
    Thanks.

    cd \
    e:
    xcopy \TEMP "\\mux-lab\zeus\TEMP" /D /E /V /Y
    xcopy \"R&D" \\juno\mux-lab\"R&D" /D /E /V /Y
    "When you hit a wrong note it's the next note that makes it good or bad". Miles Davis

  • #2
    Re: windows scheduler cannot run bat file

    Firstly, I would change the batch file to:
    e:\
    cd \
    xcopy \TEMP "\\mux-lab\zeus\TEMP" /D /E /V /Y
    xcopy \R&D \\juno\mux-lab\R&D /D /E /V /Y
    What you were doing was changing to the root of the current drive (using CD \) then changing to the E drive (e. Note also that I modified the placement of the quotes in the last line.

    Note that "/D" is defined as:

    /D:m-d-y Copies files changed on or after the specified date.
    If no date is given, copies only those files whose
    source time is newer than the destination time.

    So, using your context for this parameter, if there are no changes in your source files, nothing will be copied.

    The other thing to note is that the xcopy will only run in the context of the credentials you gave the schedule. If you gave the schedule the domain admin's credentials then it should be able to access drives on both servers. Check this by logging into your server with the E drive, but as the credentials of which you gave to the scheduled job. Then run the batch commands in a command dialog, one at a time. What happens?
    |
    +-- JDMils
    |
    +-- Regional Systems Engineer, DotNet programmer & Jack of all trades
    |

    Comment


    • #3
      Re: windows scheduler cannot run bat file

      a better idea is to use the PushD en PopD

      For example:

      Pushd e:\
      xcopy \TEMP "\\mux-lab\zeus\TEMP" /D /E /V /Y
      xcopy \"R&D" \\juno\mux-lab\"R&D" /D /E /V /Y
      popd
      Marcel
      Technical Consultant
      Netherlands
      http://www.phetios.com
      http://blog.nessus.nl

      MCITP(EA, SA), MCSA/E 2003:Security, CCNA, SNAF, DCUCI, CCSA/E/E+ (R60), VCP4/5, NCDA, NCIE - SAN, NCIE - BR, EMCPE
      "No matter how secure, there is always the human factor."

      "Enjoy life today, tomorrow may never come."
      "If you're going through hell, keep going. ~Winston Churchill"

      Comment


      • #4
        Re: windows scheduler cannot run bat file

        You can also use the /d parameter of the cd command, it allows you to change both the drive letter and the path in one command:
        http://www.microsoft.com/resources/d....mspx?mfr=true

        Sorin Solomon


        In order to succeed, your desire for success should be greater than your fear of failure.
        -

        Comment


        • #5
          Re: windows scheduler cannot run bat file

          JDMils thanks for pointing to Task schedule domain admin rights...
          It should be it. Now it's clear why batch file can run. But the scheduler can not run it. It uses local admin credentials.

          Thanks all. I will try your suggestions.
          "When you hit a wrong note it's the next note that makes it good or bad". Miles Davis

          Comment


          • #6
            Re: windows scheduler cannot run bat file

            If you're going that way, you can use the credentials page in the Properties of the task itself to run it under DomainAdmin credentials.
            Another solution might be the RunAs command. Of course that it has its drawbacks, especially the fact that the user needs to know the password or you have to write the password in the batch file in clear text. For the Domain Admin password, that might be unacceptable.
            One tool you can use is RUNASSPC. Although its encryption is breakable, eventually.

            Sorin Solomon


            In order to succeed, your desire for success should be greater than your fear of failure.
            -

            Comment


            • #7
              Re: windows scheduler cannot run bat file

              a better idea is to use the PushD en PopD

              ....

              You can also use the /d parameter of the cd command, it allows you to change both the drive letter and the path in one command:
              Wow. 2 gr8 ideas!! Well done
              |
              +-- JDMils
              |
              +-- Regional Systems Engineer, DotNet programmer & Jack of all trades
              |

              Comment


              • #8
                Re: windows scheduler cannot run bat file

                Actually, do pay attention to these things below;
                - Does drive e: happen to be a mapped drive? Because already mapped drive does not exist when you run a batch as a Task or Runas!! Map them again in the batch.
                - The user whoms credentials are used for the task must have access permissions to the share.
                - 'Relative paths' does not have to be the same folder for the 'Runas user' as they are for the logged-on user, you must set the active folder first with the /D switch.
                - When foldernames or files contain spaces, place quotes around the complete path. You can quote any path.

                You can use CD/D to switch the active folder, or, you can use PushD for the same purpose. The benefit of PushD is that you can use it with PopD to change the active directory several times. Or, use PushD when using a network path.

                The command CD/d alone does not accept UNC-paths!, you will have to map a temp driveletter first in the batch - http://forums.petri.com/showpost.php...4&postcount=12.
                If command prompt extensions are enabled in Windows XP (default), the PushD command accepts a network path. It will temporarily assigns the first unused drive letter (starting with Z:) to the specified network resource and make it the active drive. The PopD command removes the drive-letter assignation created by PushD.

                Command extensions for the command shell are enabled by default for NT shells, they provide extra features.
                However, to be absolutely sure that they are, either use SETLOCAL ENABLEEXTENSIONS within your batch or execute those using CMD /X
                (or, if you want to disable them: SETLOCAL DISABLEEXTENSIONS or CMD /y )
                OR,
                Hive: HKEY_CURRENT_USER
                Key: Software\Microsoft\Command Processor
                Name: EnableExtensions
                Type: REG_DWORD
                Value: 1 enable
                Value: 0 disable


                \Rems

                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

                Comment


                • #9
                  Re: windows scheduler cannot run bat file

                  Hello,
                  did not have time to post earlier...
                  In my case user name was Domain admins user. And not local Admin (of machine
                  from which I ran Scheduled Task).
                  I just reentered the password (Password for Domain was changed couple of month ago).
                  Probably the task existed with old password assigned. I run bat file manually once per week.

                  To make the story short. The problem is fixed. I got a lot of useful info.

                  Thanks,
                  Michael.
                  "When you hit a wrong note it's the next note that makes it good or bad". Miles Davis

                  Comment


                  • #10
                    Re: windows scheduler cannot run bat file

                    Cool. I'm glad you solved the problem.
                    Thank you for updating the forum.

                    Sorin Solomon


                    In order to succeed, your desire for success should be greater than your fear of failure.
                    -

                    Comment

                    Working...
                    X