Tuesday, December 22, 2015

Map Windows Share to a Drive Letter using batch file / command line and prompt for password

The line of code can be pasted on a command prompt in Windows 2000 and newer or pasted into a text file with a .bat extension. It will prompt the user for a password to the Windows share. The username is hard coded

@ECHO OFF
rem net use /del V:
SET /P %password%=Password:
net use v:
\\Wtjwh175\c$\dev\dropbox /u:"yourDomain\yourUsername" %password%

Technically, you will get an error saying "The local device is already in use.", if you run it twice. If you don't want that to happen you can uncomment line 2 (change rem net use /del V: to net use /del V:). This will unmap the drive and then map it again each time the batch file is executed.

No comments: