Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a task in Task Scheduler to run a batch file that resides on a local hard drive.

The batch file simply runs XCopy to copy files from a mapped drive to a folder on the local drive.

When the batch file is run from the command line, it functions perfectly.

When it's run from Task Scheduler, the XCopy command displays the error:

Invalid drive specification

If it matters, the drive is a NAS and is mapped to the computer using local credentials from the NAS (there is no active directory in the network).

share|improve this question
up vote 4 down vote accepted

I've seen this behavior before when trying to backup to a mapped NAS. I don't know why, but it needs a "nudge" to remember that X: drive is mapped to \myserver\myfolder.

Manually, this can be solved by accessing the target folder. Once you "touch" X:, Windows "remembers" it's there. Programmatically (i.e. from batch), you can either try accessing the mapped folder, or maybe even remapping it (using the net command) in the batch, before the XCopy command.

share|improve this answer
I tried several different ways of nudging. Finally issuing net use F: \\Server\Path (without re-supplying any credentials) did the trick. – Eric J. Feb 9 '12 at 19:37

This answer comes very late, but I found another way to circumvent the problem. It seems to be caused by a different context when running from a scheduled task (even if Run with highest privileges is selected), rather then from an elevated prompt.

Configure the EnableLinkedConnections registry value. This value enables Windows Vista and Windows 7 to share network connections between the filtered access token and the full administrator access token for a member of the Administrators group. After you configure this registry value, LSA checks whether there is another access token that is associated with the current user session if a network resource is mapped to an access token. If LSA determines that there is a linked access token, it adds the network share to the linked location.

  1. Start regedit
  2. Locate and then right-click the registry subkey HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System.
  3. Point to New, and then click DWORD Value.
  4. Type EnableLinkedConnections, and then press ENTER.
  5. Right-click EnableLinkedConnections, and then click Modify.
  6. In the Value data box, type 1, and then click OK.
  7. Exit Registry Editor, and then restart the computer.

Reference is here.

share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .