Windows – Access a Network drive from another user from CMD (windows)

batch-filecommand-line-interfacedaemonnetwork-sharewindows

I have written PostgreSQL backups scripts that backup all the databases to file.
pgAgent.exe (a scheduling daemon) starts the BAT scripts under the local postgres user.

The normal setup is to backup to a local drive and get the backup program to pick up the files but we have a client that would like to backup to a network drive.

I tried running pgAgent and by extension the scripts under the administration user and still did not have any luck. (same user that had the drive mappings)

When i login to the postgres user by running runas.exe /user:postgres cmd.exe and type cd /D Z: I get the error The system cannot find the drive specified.

Now from what i understand, network drives are mapped on a per user session basis. is there a special trick to accessing the network drives from a command prompt?

Best Answer

REM Mount Z:\ as the user with permissions; you may need to add the password
net use z: \\server\share /user:domain\user

REM copy things here
REM ...

REM unmount the drive letter
net use z: /d