Running BAT file in task scheduler WIN7 Pro


  • I have a bat file that uses xcopy to copy a directory on the local hard drive to a mapped drive (X:). The mapped drive is a share on a Windows Vista machine and when connecting it requires the user name and password of an account on the Vista Machine to connect. There is no server on the network, just two Vista ultimate and 2 win7 pro.


    If I run the bat file manually this works perfectly. When I create a scheduled task using Task Scheduler to do this it never runs. I have used cmd \c as part of the schedule but it simply does not start. When I look at the task history it tells me it has run though.


    I am unsure why this is happening? Could it be that that as the mapped drive requires a different user name and password to that of the local machine it is failing? The curious thing is the bat file works fine if I do it manually and the mapped drive is always present.


    Any ideas how I can get this task to schedule correctly?


    Tuesday, March 29, 2011 9:23 AM


All replies

  • Hi,



    If this bat file works fine when you run it manually, it should be related to the settings about task schedule.


    Please check the following settings in Task Properties:


    In General tab, check Run with highest privileges.

    In Actions tab, click on the action and then the "edit" button at the bottom. In the "Edit Action" Window there is a field for "start in (optional)", please set the path for your bat file.


    Hope it helps.


    Alex Zhao

    Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread.
    • Proposed as answer by ITBM Thursday, March 31, 2011 12:20 PM
    Thursday, March 31, 2011 9:55 AM
  • Hi thanks for your reply! But I’m afraid this didn’t work.

    I did play around with the action settings and found if I set program/script to 'cmd' and add arguments to '/c C:\BatchFile.bat' the batch file runs on schedule ok.

    But if in the task properties under general I select to 'Run whether user is logged on or not' it only runs if the xcopy destination is on the local drive. If I set it to my mapped network drive (X:) or a network path it doesn’t even start - if I set up a log file I get no errors!

    When set to 'Run when user is logged on' it works perfectly regardless of where the destination folder is (local or network).

    I need to be able to schedule this task to copy files to a network location overnight regardless of where the user is logged on or not!

    So this works:

    xcopy "C:\DIR1\*" C:\DIR2\*  /y /d /s /e /c /I /h /r /k

    But this doesn’t (X: is mapped network drive):

    xcopy "C:\DIR1\*" X:\DIR2\*  /y /d /s /e /c /I /h /r /k

    or this:

    xcopy "C:\DIR1\*" \\OTHER-PC\DIR2\*  /y /d /s /e /c /I /h /r /k

    Could this be because my network path (shared from a Vista Business machine) requires authentication user name and password which are different from the local machine? But I don’t understand why if this is the case the bat file didn’t start up then log an error?


    Friday, April 01, 2011 7:42 AM
  • i resolve dthis by using the ipaddress of the share location:

    xcopy "C:\DIR1\*" "\\\ShareFolder\DIR2\*" 


    Monday, April 04, 2011 11:38 AM
  • I have been struggling with this for a few days. My bat file shares external drives. Like others it works fine when executed either from cmd or just double click. I added net share > log.txt at the top of the bat file to see what was up. The message in log.txt said that the Server service was not running and did I want to start it. Since I am trying to share drives at startup and not after I'm  logged in, I was wondering if there was a timing issue. That is, something was not started when I tried to use the net share command. So I added timeout /T 30 /nobreak at the top of the bat file. This makes the script wait 30 seconds before running any net share commands. So far so good. I'm not sure which service is not starting fast enough, or if it is something else, but you might give this a try. By the way, the timeout command may be restricted to Vista/Win7.

    nmmom's hubby (her account)

    • Proposed as answer by NMProf Saturday, April 14, 2012 2:20 AM
    Saturday, April 14, 2012 2:05 AM
  • OP has long since solved his problem, but this may help someone else:

    I had a similar problem. Task Scheduler wouldn't even run a simple batch file saying

    echo Hello

    In my case I found I had to do two things:

    1) Use double quotes to enclose the complete path of the Program/Script in the 'Action' area. This was even though I'd used the built-in 'Browse' facility to locate it. (It was not necessary to use the 'Start in' field.)

    2) Remove an ampersand (&) that happened to be in my filename. Task Scheduler seemingly couldn't cope with the &, even though the file ran OK outside of Scheduler.

    So, in the Action area:


    needed to become:


    Then all was well.

    • Proposed as answer by Mutaupi Friday, September 28, 2012 8:18 AM
    Friday, September 28, 2012 8:16 AM
  • I could kiss you. 

    I was going fscking bananas, and the discovery that the system here had an ampersand in it that did exactly the evil you spoke of has released me from the bonds of hell.

    Alas, it was in the pathname on a corporate system that I have no ability to change, so the bat file lives in a cave now.

    Monday, November 04, 2013 8:34 AM
  •  the discovery that the system here had an ampersand in it that did exactly the evil you spoke of has released me from the bonds of hell.

    Alas, it was in the pathname on a corporate system that I have no ability to change, so the bat file lives in a cave now.

    You can retrieve your batch file from its cave and resolve the problem by surrounding the path name with double quotes, e.g.  like so:

    cd "Sales & Purchasing"

    That's all that's needed . . .

    Monday, November 04, 2013 9:38 AM