Batch file---Map network drive authenticating with UN and PW

I have a small XP network (Workgroup) with a network hard-drive that we are using for a backup. My predecessor created a backup schedule thru Robocopy but my problem is that the network drive is password protected and the backup fails each evening with Access is denied.
The backup is from a single XP machine acting as a file server. The system has multiple users who log in and out with the same mapped drive to the backup drive, but when users log out it drops the mapped drive.
So I need to add some commands to the batch file. Mapping the network drive and authenticating with the username and password. Then waiting a few seconds before continuing with the backup.
Is this possible with a Batch file? I have searched the internet and am coming up blank.

The IP of the network drive is the Below is the batch file as it currently stands:
robocopy "C:\Investments" "I:\BACKUPS" /MIR /V /NP /R:10 /W:5 /log:C:\Nightly_Backup_log.txt

Thanks in advance for any help.
Who is Participating?
hlarseConnect With a Mentor Commented:
Try this:

net use i: \\server\share /user:userid password
ping -n 6 >nul
robocopy "C:\Investments" "I:\BACKUPS" /MIR /V /NP /R:10 /W:5 /log:C:\Nightly_Backup_log.txt

The ping functions as a pause.
Steve KnightIT ConsultancyCommented:
You don't need to pause after mapping a drive, it is either mapped or not but otherwise as hlarse says.

You can also do it by scheduling the backup task as, say, a local username called "userid" with a password of "password" (obviously use real values here) which matches the userid and password on the machine to be backed up to.  Then if you backup using

robocopy "c:\investments" "\\otherpcname\share" /MIR .... etc.

it should work as it will use current username and password to access the UNC


AZHenryAuthor Commented:
It worked like a charm, mapped the drive and authenticated with no glitches. I didnt run robocopy but am sure it will go thru tonight. Thank You

Also thank you for your input as well, as to batch files this has been a good learning experience and I appreciate your suggestions.

Im going to award all points to hlarse since his was the 1st response and provided exactly what I needed.

Steve KnightIT ConsultancyCommented:
Fair enough.... 3 minutes late, was just about to post but saw hlarse's first :-)
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.