Network drive mapping batch file that passes domain username/password

Pro4ia
Pro4ia used Ask the Experts™
on
Experts,

I have a need for a batch file that can be executed while the user is connected via VPN to the office network. This batch file must map a few generic shares and then the user's home folder. After some research I wrote up the following:

if exist z: net use z: /delete
if exist y: net use y: /delete
if exist t: net use n: /delete

net use z: \\192.168.10.252\Share1 /persistent:No
net use y: \\192.168.10.252\Share2 /persistent:No
net use t: \\192.168.10.252\users$\(users username) /persistent:no /u:domain\username password

To answer a few of the potential questions - I used the IP address rather than the hostname of the server to avoid having any DNS issues. I originally tried using the %username% variable but changed to using the actual username since I will have to have an independent file for each user that stores their credentials (not a big problem, small office with only ~3 users who would need this capability).

The paths are all correct, if I were to do start>run with the path to the home folder and type in his credentials it works fine. Just can't seem to convince the batch file to pass that info correctly.

OS is XP, server is WS2008, VPN client is Cisco.
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
I dont know if it's related, but I noticed an error:
if exist z: net use z: /delete
if exist y: net use y: /delete
if exist t: net use n: /delete       Shouldn't this read "t"?

Author

Commented:
Yes, it should and it does, I made an error when I copied the text over and deleted some extra lines.
Commented:
TheQuietShadow he has the right syntax for the before and after, although i always used /user: instead of /u:
e.g.  net use x: \\server\share /user:domain\username P8ssw0rd
Pro4ia can you open a command prompt and then run the script from there and paste back the results?

Author

Commented:
Making the following changes produced the desired result. TheQuietShadow was correct regarding the syntax, /user needed to be used instead of /u. The order of the password did not matter. I added the credentials to the first drive the script attempts to map.

if exist z: net use z: /delete
if exist y: net use y: /delete
if exist t: net use t: /delete

net use z: \\192.168.10.252\Share1 /persistent:No /user:domain\username password
net use y: \\192.168.10.252\Share2 /persistent:No
net use t: \\192.168.10.252\users$\(users username) /persistent:no

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial