Link to home
Start Free TrialLog in
Avatar of jforville
jforville

asked on

Prompt for User Credentials in BAT file

How do I ask the user to supply a network username/password when connected to a network via a VPN connection?  For example, I want to run the following command from a BAT file:
xcopy \\<servername>\<sharename>\*.atp "C:\PfX Documents\Binder\Templates\*.*" /D.  It's easy enough when I do the Net Use command and map to a device, since the OS (Win2000/XP) will prompt for a username.  But without running the Net Use command, as in my example, I just get the message "Invalid Drive Specification".  It will work fine if I first do a Run command using \\<servername> and ride username/password.  However, I am trying to prevent the users from doing anything other than connect to the VPN and running a BAT file.  The connecting PC's are not members of the Domain, but the users are.
Avatar of Lee W, MVP
Lee W, MVP
Flag of United States of America image

Sorry, don't think it can be done as you describe.  You can use net use and I'm not entirely sure why you don't want to.  For example:, this little batch file will do the trick for any NT4/2000/XP system.

net use x: \\server\share * /user:domain\username
xcopy \\<servername>\<sharename>\*.atp "C:\PfX Documents\Binder\Templates\*.*" /D
net use x: /delete
ASKER CERTIFIED SOLUTION
Avatar of Lee W, MVP
Lee W, MVP
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of tengage
tengage

I'm not real sure what you're asking.  

If you wanted to be very unsecure, you could add the net use to the batch file and give it the ID and password, or you could give it the ID and let the batch prompt for the password.

net use x: \\server\share /u:user password
xcopy x:\*.atp c:\templates\*.*
net use x: /d

If you do the NET USE and don't provide the password, your users will get this in when they launch it

Enter the password for 'user' to connect to 'server':
wow, we even used the same drive letter
Actually as I think about it, if you are copying files via UNC, you don't even need to make a drive letter.  You could do this:

set /p useris=Please Enter Your Username:
net use \\server\share * /user:domain\%useris%
xcopy \\<servername>\<sharename>\*.atp "C:\PfX Documents\Binder\Templates\*.*" /D
net use \\server\share /delete

(Also, the "/p" in the set command will prompt the user with the text following the "=" sign and whatever the user types in will be assigned to "useris")
Avatar of jforville

ASKER

Thanks, it was the /p I was looking for.