Navigation

6/04/2013

Mapping Drive for all users in Windows 7

Want to map drive for all users in Windows 7, but NOT using Active Directory, or Group policy.  Here is using .bat script:



Open your prefered text editor such as notepad or notepad++. (You will have to run-as-admin if you have UAC enabled due to where we will be saving it.)

Type in your code:
@Echo Off
Net use P:
\\Server\Share1 /Persistent:No
Net use Q:
\\Server\Share2 /Persistent:No
Net use G:
\\Server2\Share3 /Persistent:No

I used /Persistent:No because I am confident in the server connectivity and do not want to have to use a Net Use [Drive] /Delete in order to remove drives later. The script will be running everytime at each logon so I did not feel the need for it to reconnect itself.
You may use a /Persistent:Yes if you wish, but this means that the drive will remain even if you later remove it from the logon script. As mentioned above, you can counteract this with a net use [drive] /delete.

Save the file as a .bat file to %ProgramData%\Microsoft\Windows\Start Menu\Programs\Startup
Example:
C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Startup\

If you need to specify alternate credentials, you can do so with "Net Use Z: \\Server\Share /User:Domain\Username Password" but be warned, this will save the password in plain text for anyone to read. And the script will be quite easily findable as it will be in everyone's StartMenu -> Programs -> Startup folder. (Which means it's also easy for users to re-run the script if they've lost their drives for some reason. Or they could just log out and back in.)

This will also work for other Windows operating systems, even Windows 8 despite not having a Start Menu (the files are still there, and I can confirm that items in the startup folder will be run at logon), but the location you need to save the script in might be different. If you right click on the folder in the start-menu, you can generally get the opion to "Open All Users". This should let you know where it is. Except for Windows 8 obviously... stupid not having a start-menu... Pretty sure it was in the same location as Windows 7.


---------------------------------

net use [{devicename | *}] [\\computername\sharename[\volume] [{password | *}]] [/user:[domainname\]username] [/user:[dotteddomainname\]username] [/user:[username@dotteddomainname] [/home {devicename | *} [{password | *}]] [/persistent:{yes | no}] [/smartcard] [/savecred] [/delete] [/help] [/?]


devicename = Use this option to specify the drive letter or printer port you want to map the network resource to. For a shared folder on the network, specify a drive letter from D: through Z: and for a shared printer, LPT1: through LPT3:. Use * instead of specifying devicename to automatically assign the next available drive letter, starting with Z: and moving backwards, for a mapped drive.
\\computername\sharename = This specifies the name of the computer, computername, and the shared resource, sharename, like a shared folder on a or shared printer connected to computername. If there are spaces anywhere here, be sure to put the entire path, slashes included, in quotes.

volume = Use this option to specify the volume when connecting to a NetWare server.

password = This is the password needed to access the shared resource on computername. You can choose enter the password during the execution of the net use command by typing * instead of the actual password.

/user = Use this net command option to specify a username to connect to the resource with. If you don't use /user, net use will attempt to connect to the network share or printer with your current username.

No comments:

Post a Comment