Map a network space to a Windows Drive in a scheduled job (script)?

Solution 1:

Mapped drives are only available to an interactive session. You can't map a drive while running as a service, you need to use UNC paths.

Solution 2:

I faced a similar issue. When I was trying to schedule a task and browse the script as action, the mapped drive was not even being displayed. I remapped the drive in the window that opened while browsing the file in the file system. After that it worked fine for me.

Steps I followed:

  1. Open Task Scheduler

  2. Create a new task with all details, triggers etc needed.

  3. Go to actions -> Select the action from the drop-down list -> Click on "Browse"

(This opened the browsing window)

  1. Right Click on Computer -> Map Network Drives -> Map the drive required

  2. Attach the file to the job

Done

Cheers!!

Solution 3:

net use S: \\netdrive1\space1 pwd /user:oneUser /persistent:yes

That might do away with the need for the scheduled task but I'm not sure if it will maintain the connection without a user logon.

UNC paths in your application is a much better way than mapping the drive so if possible you should do that instead.

http://technet.microsoft.com/en-us/library/bb490717.aspx

EDIT

This is not very elegant but it might work (completely untested)

NET USE \\netdrive1\space1 /USER:oneUser pwd && PUSHD \\netdrive1\space1
COPY C:\path\to\files\*.dat Z:\
POPD && NET USE \\netdrive1\space1 /DELETE

Try that as your batch file. What's happening is NET USE authenticates the user against the share, PUSHD automatically mounts the drive to a drive letter (in reverse order so assuming no other drives are mounted, which there isn't in this case, it will be Z:). Copy the files then kill the connection to the share. I have no idea if this will work without interactive login session but it's worth a shot.