Categories / Scripting / Batch scripts

Batch script to map network drives and printers

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
  

Batch script to map network drives and printers

Comments (8)

 

Tamrat 22-06-2011 10:32
I've been searching almost all week to map network shares with bat scripts..and finally i've found it on this site...finally...!!! thanks guys ur the best...
 
Arun 03-11-2011 08:35
thanks buddy
 
Amit sharma 24-12-2011 21:25
Guys,
I want to map a shared drive on my remote computer by using my local computer..how it is possible??

Thanks,
Amit
 
Wayne Riesterer 16-09-2012 10:25
Thanks :)
 
Tiplu 17-09-2012 20:24
Thanks for the valuable post.
 
Tinning 20-03-2013 04:07
I want to map more then 1 drive to specific users on the net with .bat scripts. Is it possible? How?

thanks in advanced...
 
Tinning 20-03-2013 04:13
I want to map more then 1 drive to specific users on the net with .bat scripts. Is it possible? How?

thanks in advanced...
 
Al Conrad 01-04-2013 19:07
I have a persistently mapped drive that needs to be accessed by a IIS ASP.NET application. It looks like I need to imbedded a valid domain user and password which has both login to the server and access to the network share for it to work. Is there any other way to give access to IIS without an ID with login rights?
 

Comment on this article

Name
Email (receive replies)
Comment
What is: 10 + 3
 

Valid XHTML 1.0 Transitional Valid CSS! Subscribe to RSS feeds from my blog about all aspects about system administration in a Microsoft Windows server environment