Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 8101
  • Last Modified:

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.
0
jforville
Asked:
jforville
  • 3
  • 2
1 Solution
 
Lee W, MVPTechnology and Business Process AdvisorCommented:
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
0
 
Lee W, MVPTechnology and Business Process AdvisorCommented:
The "*" prompts for the user's password.  Actually, this might be a little better for you:

set /p useris=Please Enter Your Username:
net use x: \\server\share * /user:domain\%useris%
xcopy \\<servername>\<sharename>\*.atp "C:\PfX Documents\Binder\Templates\*.*" /D
net use x: /delete
0
 
tengageCommented:
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':
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
tengageCommented:
wow, we even used the same drive letter
0
 
Lee W, MVPTechnology and Business Process AdvisorCommented:
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")
0
 
jforvilleAuthor Commented:
Thanks, it was the /p I was looking for.
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now