Categories /
Scripting /
Batch scripts
Network folders and printers on a file server can easely be attached to the local computer using the build-in functions in Microsoft Windows, but sometimes it can come handy to map network drives and printers using a script to make sure all users get the same drives and printers or to differentiate the drives different groups of users get based on their relation to departments etc.
The batch script to map a network drive is something like the following:
Net use x: \\fileserver\serverShare
Where x: is the drive letter to assign to the new drive in Windows and the rest is the UNC path to the shared folder on the fileserver.
The default is that the mapped network drive will disappear at the next reboot.
To make it persistent, add the following to the script:
/persistent:yes
The script will now look like:
Net use x: \\fileserver\serverShare /persistent:yes
Map network drive with different credentials
Using different credentials than the currently logged on user who executes the script is also possible.
Use the same script as above, but add the /user parameter to the script adding the username and password:
Net use x: \\fileserver\serverShare /user:administrator Password /persistent:yes
Here the /user:administrator is the user whos credentials we use to map the network drive and Password is the users password.
Mapping network printers using batch scripts
Actually the same goes for printers, except that we do not assign them a drive letter.
Lets say we want to map a printer on a server called fileserver with the shared name sharedPrinter. We would use the following script:
Net use \\fileserver\sharedPrinter /persistent:yes
If the user executing the script has permissions to print on this printer, the printer will be mapped and be available after the next computer reboot.
30-06-2009 by Thomas Møller Nexø
Unique visits since publich date
36867
Comments (8)
Comment on this article