KWSupport

Kevin Weilbacher [SBS MVP] blog on SBS, WHS and other topics of interest!

Recent Posts

Tags

News

  • Check out the "Song of the Week" link!
    Xobni outlook add-in for your inbox

Community

Email Notifications

SBS Blogs

SBS2003 Links

Archives

Batch file to map network drives for users

Often it is asked how to create a batch frile to map network drives for users at logon. Here's how I did it at one site where I had a small number of users, but each user had a different set of mapped drives they needed to access.

Note, in this posting, “sbs1“ is the name of my SBS server. Substitue your SBS server name accordingly!

Location of script: The default SBS login script is located at c:\windows\sysvol\sysvol\sbs1\scripts and the script file is SBS_LOGIN_SCRIPT.bat.

Note: a quick way to get to this directory is to click Start > Run, and then enter \\sbs1\netlogon - and you will be right there, with no further drilling down any subdirectories!

1. First thing you want to do is to make a backup copy of the .bat file - just in case!

2. Next, edit the contents of the default .bat file so it looks like this, and then save it.

Rem Default SBS Login Script for users
\\sbs1\netlogon\%username%.BAT

3. I then created a new .bat file for each user. The name of the .bat file explicitly matched their actual logon name. So, if you logged on as JohnDoe, then the batch file was named JohnDoe.bat

Here is the content of one such user batch file:

Rem Batch  File for user John Doe
NET USE Q:
\\sbs1\Quickbooks
NET USE S: \\sbs1\SharedCompany
NET USE T: \\sbs1\Access

So, what happens is that when John Doe logs in, the default SBS script is started and immediately starts up the script file johndoe.bat, which has the various mapped drives to be declared.

4. Now, all you need to do is to create a new batch file for each user - no need to mess with the default SBS script any more. And no need to modify the name of the startup login script from within AD.

Add a new user? Simply add a new batch file!

Posted: Wed, Nov 3 2004 20:37 by kwsupport | with 45 comment(s)
Filed under:

Comments

kwsupport said:

thanks!
# November 30, 2004 3:11 PM

kwsupport said:

I understood that you could do create login maps with the Organization Unit but that is my limits (SBS2003) I need help with this.
# December 11, 2004 2:06 PM

kwsupport said:

What about the default contents of the SBS_Login_Script.bat file?
i.e. \\sbs1\clients\setup\setup.exe /s sbs1
What does this executable do? Can I just delete it from the default login script. Never had to bother with this in regular Windows 2003 Server. 1st time installing SBS.
# December 23, 2004 12:05 AM

kwsupport said:

Re: the contents of the default login script

I think that the \\sbs1\clients\setup\setup.exe /s sbs1 is used by Small Business Server to configure new computers.

When you configure a new computer using the Small Business server wizards, I am almost certain that this is the application that runs at each logon prompting the user to install the clients (i.e. Outlook).

I would suspect removing this line would mean automatic application installation will fail.
# January 17, 2005 10:48 PM

kwsupport said:

You may want to preface each net use command with
"NET USE <driveletter>: /DELETE"

If for some reason there's a previously mapped drive, not using this command will cause the map to fail.
# March 16, 2005 1:46 AM

kwsupport said:

Chris,

Do not delete the default logon script.
It does more than just setup new computers, you add.
It also reapplies some sbs gpo's in case they have been altered, amongst other things. It also is used by the add software Wizard should you run it.

If you are going to be adding lines to the deafult logon script, I would highly recomend adding each line as a call statement, rather than just a line. other wise if you add 2 or more lines, there is the potential for some of them to not fire off. By using call you force the focus back to the defalut logon script after excecution of your new line.
So to use Kevin's example you would add

Call \\sbs1\netlogon\%username%.BAT

So your new default logon script would read

Rem Default SBS Login Script (First Line Always)
Call \\SBS1\Clients\Setup\setup.exe /s SBS1

Rem Default SBS Login Script for users
Call \\sbs1\netlogon\%username%.BAT

Rem Default SBS Login Script for Additional Command
Call \\SBS1\netlogon\AnotherBatchFile.bat

:End

This will ensure all the lines in your logon script get a chance to fire off.

Goog Luck,

HandyAndy a.k.a. Andy Goodman [SBS-MVP]
www.SBS-Rocks.com
# March 16, 2005 8:24 AM

TrackBack said:

^_^,Pretty Good!
# April 13, 2005 11:52 PM

kwsupport said:

i need help with creating a batch file wich will map a network drive and create a shortcut of the file in that drive and place it in the all users startup can anyone help?????

Renegades@techie.com
# May 3, 2005 2:50 AM

kwsupport said:

I wonder if there is a way to make a startup script that would check if there are already drives mapped for this user, remove some of the mappings, according to their UNC, and add new ones with a path based on the org. unit that the user's account is in. That probably calls for some VBScripting...
# July 26, 2005 1:17 PM

kwsupport said:

I am trying to map network drives using a batch script. I am at a university for an IT dept so naturally I have many drives to map, and across 3 of our domains. All domains have different logins, so the batch script prompts me to login to those domains as it maps drives for each domain. Is there a way to set the login in a batch script (this is a private file on my pc in an encrypted and protected folder) to login automatically to those domains for those mappings?
# September 23, 2005 10:07 PM

kwsupport said:

Hi,

I'm just starting to try things using batch files, and was writing this. But it doesn't work if my folder has a space in it, ie \\example\sub folder
Is there a way to overcome this?
# September 26, 2005 6:33 AM

kwsupport said:

Andy,
I saw that you are an SBS mvp. I have an issue that Microsoft was of little help for. I am using a PowerEdge 600SC, and i am attempting to use the software raid within sbs 2003. Everytime I tell it to create the mirror it gets to 4% and stops. The error log reads Drive0 has a bad sector. That is all it says and it will not copy over. I have run error checking and the drive has no problems, system runs great as a matter of fact. However i want to run RAID 1 to mirror in case of a drive failure, please help........
# September 26, 2005 1:25 PM

kwsupport said:

Can you map drives via group policy?
# November 11, 2005 6:21 PM

Eric Montgomery said:

I am actually brand new to server OSs, but experienced with 9X and up to XP Pro in Home/Home Office conditions.

All of this information is amazingly helpful, but was wondering if someone could tell me how I can send any user connecting via terminal services to see the Intranet Site?

Thanks,
Eric - shoregeek@gmail.com

# January 22, 2006 10:12 PM

AJ said:

Thanks very much for your help !
# June 15, 2006 12:40 PM

Paul Wilson said:

When using the above script to map users folder space the command fails becuase it appears to require the users password. Do you have any suggestions as to how to get around this?

Example:

NET USE M: \\Users Shared Folders\PaulWilson

This just doesn't work!
# July 3, 2006 4:55 PM

Sam said:

NET USE M: \\Users Shared Folders\%paulWilson%
# August 29, 2006 6:12 AM

Joe Schilla (JoeSchilla@comcast.net) said:

Re: SBS_login_script.bat
Question related towards the logon script.
My server right now has about 5 users that actually have the
default sbs_logon_script.bat  in the active directory profile. these where setup before i started with this company i figure thats becasue of wizard use on setup of those accounts.
But my problem is on those accounts and those accounts only. They will not accept passord changes well they can be changed in active directory and on user logon but when accessing a network drive they are told that it is invalid and when trying to go directly to the server through network places they are prompted for their password and the system will not take it and the have no access to the network file system
but if i go back to active director and change thier pass back to thier
original password everthing works fine.
i have also tried removeing the login script from the user profile no luck
none of my othere user use a logon script period
and have no issue and the drives are mapped on startup

I've searched every where for a solution to the problem with no luck
I have read that it might take 24 hours for it to re-populate and that sounds wierd to me since the other password changes are instant.

But i am no master at this i am what you guys would refer to as the accidental technoligist
I hope i described this issue properly and any help or corrections would be greatly appreciated
p.s.
I also read that changing the script so that it deletes and remaps the drives could be a solutioin
thanks again

# September 1, 2006 4:28 PM

Brett said:

As an alternative to deleting the mapped drive prior to mapping it (in the event that the mapping is remembered after reboots), you can also use the following: if not exist S:\. net use S: \\sbs1\share This will check for the existence of the S: drive prior to mapping it. (so trying to remap a mapped drive just generates an error message and exits, its no biggie, but this is at least a little cleaner). Brett
# September 28, 2006 7:35 AM

Brett said:

Sam / Paul Wilson... it looks like you are trying to map a share without specifying a server.. "\\users shared folder\" is not a valid server name - '\\sbs1\users shared folder\username' is. So: net use M: '\\server\users shared folder\PaulWilson' should work. You can also use the "/persistant=yes" switch at the end to keep the connection active.
# September 28, 2006 7:38 AM

Michael Frank said:

I tried 2 scripts to map from one drive to another during everyday work. Maybe 10 times a day. After a while the OS does not recognize the remap command and a reboot is required. Any comments? Michael Frank
# October 16, 2006 10:38 AM

Rahul said:

I need to create shortcuts for a network computer folders ...I need to create a batch file which when I run connects to the network computer and maps and creates the links for all the files inside it .I do not want to copy the contents of the file but just links as the server has about 1 terrabyte of data.

If i am able to give the users the batch file , they will be able to just go to their c: drive open the folder and use the file...

e.g. I have a computer named \\rahul which contains 100 folders ...It shud copy the folders and when someone opens a peculiar folder it shud show the files in it locally ..... , and show him the files that are there ...FILES when "clicked" shud go to the network computer (\\rahul) and play the same.

PLEASE HELP ..IT WILL BE HIGHLY APPRECIATED

# January 9, 2007 8:32 AM

Erlin said:

and the last one is to map your drive for many diferrent user just with one file....

net use Z: \\dellserver\users\class_2009\%username%

this one is to set permission on the directory.... it work's

@echo off

setlocal enabledelayedexpansion

D:

cd\Users\Class_2009

for /f %%a in ('dir/ad/b') do (

set strUser=%%a

cacls .\!strUser! /T /E /G !strUser!:F

)

This Batch files is to create directory and it will save you a lot of time if you have to create 100 folder for diferrent user in the network................. it work's i try it...

md D:\users\class_2009\ACamara

md D:\users\class_2009\ACarotenuti

md D:\users\class_2009\AWebster

md D:\users\class_2009\AAlbizu

md D:\users\class_2009\APaz

md D:\users\class_2009\ABaker

md D:\users\class_2009\AAlcantara

md D:\users\class_2009\AAuclair

md D:\users\class_2009\APlunkett

md D:\users\class_2009\ATavarez

md D:\users\class_2009\AFonseca

md D:\users\class_2009\ASilva

md D:\users\class_2009\AOwen

md D:\users\class_2009\ASalisbury

md D:\users\class_2009\ARabel

md D:\users\class_2009\AFeliz

md D:\users\class_2009\AMercedes

md D:\users\class_2009\APerez

md D:\users\class_2009\APimentel

md D:\users\class_2009\AVega

md D:\users\class_2009\AKing

md D:\users\class_2009\BSalon

md D:\users\class_2009\BJohnson

md D:\users\class_2009\BEsposito

md D:\users\class_2009\BReeves

md D:\users\class_2009\BSanchez

md D:\users\class_2009\BSanchez

md D:\users\class_2009\CMcGrath

md D:\users\class_2009\CPerez

md D:\users\class_2009\CGarcia

md D:\users\class_2009\CMorris

md D:\users\class_2009\CEfros

md D:\users\class_2009\CMelendez

md D:\users\class_2009\CDacosta

md D:\users\class_2009\CHughes-Barnes

md D:\users\class_2009\CAdams

md D:\users\class_2009\CSang

md D:\users\class_2009\CDoran

md D:\users\class_2009\CHopkins

md D:\users\class_2009\CGonzalez

md D:\users\class_2009\CAvila

md D:\users\class_2009\CSenice

md D:\users\class_2009\CGoncalves

md D:\users\class_2009\CWise

md D:\users\class_2009\CPena

md D:\users\class_2009\DChacon

md D:\users\class_2009\DPena

md D:\users\class_2009\DHerberman

md D:\users\class_2009\DClanton

md D:\users\class_2009\DAzzam

md D:\users\class_2009\DLeggett

md D:\users\class_2009\DDale

md D:\users\class_2009\DRutledge

md D:\users\class_2009\DSpears

md D:\users\class_2009\DJordan-Brown

md D:\users\class_2009\DJackson

md D:\users\class_2009\DBarta

md D:\users\class_2009\EThomas

md D:\users\class_2009\ELevine

md D:\users\class_2009\EWelch

md D:\users\class_2009\EYoung

md D:\users\class_2009\EAcevedo

md D:\users\class_2009\EAnderson

md D:\users\class_2009\EUrena

md D:\users\class_2009\EMcDermott

md D:\users\class_2009\EReynoso

md D:\users\class_2009\FDesousa

md D:\users\class_2009\FOlajide

md D:\users\class_2009\FGomez

md D:\users\class_2009\FMarzan

md D:\users\class_2009\FPerez

md D:\users\class_2009\GTetreault

md D:\users\class_2009\GSemedo

md D:\users\class_2009\HMcCormack

md D:\users\class_2009\HBarlow

md D:\users\class_2009\HGranandos

md D:\users\class_2009\HReyes

md D:\users\class_2009\HLafitte

md D:\users\class_2009\IHess

md D:\users\class_2009\JLopes

md D:\users\class_2009\JJohnson

md D:\users\class_2009\JRose

md D:\users\class_2009\JSanchez

md D:\users\class_2009\JEhrenberg

md D:\users\class_2009\JRoland

md D:\users\class_2009\JMerlain

md D:\users\class_2009\JPerez

md D:\users\class_2009\JTejada

md D:\users\class_2009\JVillegas

md D:\users\class_2009\JAmadiz

md D:\users\class_2009\JMejia

md D:\users\class_2009\JBrito

md D:\users\class_2009\JColon

md D:\users\class_2009\JMaddox

md D:\users\class_2009\JMolina

md D:\users\class_2009\JPerez

md D:\users\class_2009\JGendron

md D:\users\class_2009\JBlackbear

md D:\users\class_2009\KDulude

md D:\users\class_2009\KTavarez

md D:\users\class_2009\KOrellana

md D:\users\class_2009\KBarry

md D:\users\class_2009\KFournier

md D:\users\class_2009\KDacruz

md D:\users\class_2009\KBranch

md D:\users\class_2009\KAult

md D:\users\class_2009\KDavis

md D:\users\class_2009\KAndrade

md D:\users\class_2009\KGarcia

md D:\users\class_2009\LSpears

md D:\users\class_2009\LWilliams

md D:\users\class_2009\LTorres

md D:\users\class_2009\LLanory

md D:\users\class_2009\LOk

md D:\users\class_2009\LDeJesus

md D:\users\class_2009\LJeanlouis

md D:\users\class_2009\MSprague

md D:\users\class_2009\MPettaway

md D:\users\class_2009\MGonzalez

md D:\users\class_2009\MBonnenberg

md D:\users\class_2009\MNunez

md D:\users\class_2009\MSheppard

md D:\users\class_2009\MFlaquer

md D:\users\class_2009\MTurino

md D:\users\class_2009\MCarrasco

md D:\users\class_2009\MFigueroa

md D:\users\class_2009\MDowning

md D:\users\class_2009\MSanchez

md D:\users\class_2009\MTurcios

md D:\users\class_2009\MVasquez

md D:\users\class_2009\MKeo

md D:\users\class_2009\NDrolet

md D:\users\class_2009\NBaillargeon

md D:\users\class_2009\NChartier

md D:\users\class_2009\NPerez

md D:\users\class_2009\NCoronado

md D:\users\class_2009\NHartland

md D:\users\class_2009\NJordan

md D:\users\class_2009\NPelletier

md D:\users\class_2009\NPrimiano

md D:\users\class_2009\NSoko

md D:\users\class_2009\ODiaz

md D:\users\class_2009\ORichardson

md D:\users\class_2009\OVelasquez

md D:\users\class_2009\PTejada

md D:\users\class_2009\PDulude

md D:\users\class_2009\PFallago

md D:\users\class_2009\PCastillo

md D:\users\class_2009\RPerdomo

md D:\users\class_2009\RGil

md D:\users\class_2009\RCameron

md D:\users\class_2009\RFlores

md D:\users\class_2009\RDacosta

md D:\users\class_2009\RCharette

md D:\users\class_2009\RShaw

md D:\users\class_2009\SPao

md D:\users\class_2009\SMartino

md D:\users\class_2009\SRobinson

md D:\users\class_2009\SRusler

md D:\users\class_2009\SLoch

md D:\users\class_2009\SLove

md D:\users\class_2009\SHuffman

md D:\users\class_2009\SRoss

md D:\users\class_2009\SFofana

md D:\users\class_2009\SBrett

md D:\users\class_2009\SLuna

md D:\users\class_2009\SMontes

md D:\users\class_2009\SRivas

md D:\users\class_2009\SNgo

md D:\users\class_2009\TKerby

md D:\users\class_2009\TSuarez

md D:\users\class_2009\TClements

md D:\users\class_2009\TJake

md D:\users\class_2009\VPoirer

md D:\users\class_2009\VPerez

md D:\users\class_2009\WHenderson

md D:\users\class_2009\WMoura

md D:\users\class_2009\WAmparo

md D:\users\class_2009\XVang

md D:\users\class_2009\YSostre

md D:\users\class_2009\YDiaz

md D:\users\class_2009\ZVang

# January 13, 2007 10:08 PM

William Watson said:

Interesting read!  I've just decided to ditch our Novell server (IPX) where mapping network drives was a doddle.  But I'm migrating to Linux, not MS SBS I'm afraid.  

The Novell system was brilliant in its own way, never once stopped and very fast - but I can't face reinstalling it on new hardware and the technology has been overtaken....

# January 21, 2007 10:28 AM

Wesley said:

I use the net use command to map the drives on the users logon but i want to hide the drive after it maps it so the users can not go under my computer and see it. It is a drive that has software that is programmed to work on all the clients as a database for inventory changes. So i still need it to map in a way so the clients can still use the program on the server. Any ideas Thanks!

# February 14, 2007 10:46 PM

Tony D said:

Can anyone tell me if there is a way of renaming the name of the drives that are mapped for example.

net use S: \\mnltegb05\server\database

will be displayed in Windows Explorer as

(S:) database on 'mnltegb05\server'

If I want the network mapping to be displayed as

(S:) DB

...is there an option to do so?

thanks

# March 11, 2007 9:32 PM

Tito said:

Can someone please tell me how to apply these principles to include two printers

\\192.168.1.47\CLR (color)

\\192.168.1.47\BNW (black and white)

with the BNW as the default printer and also create a shortcut of the home directory on the users desktop.

Any help please e-mail me to tito7769@gmail.com. Thank you so much!

# March 14, 2007 8:44 AM

Cyrus said:

I have the following in a batch file. I want a VBS script to change the batch file password "Startrek" after the user has been required to change the password through another automated process. Any suggestions?

net use u: \\Servername\Sharedfoler Startrek /User:NA\cyrus.t.andrews

# March 28, 2007 10:21 AM

abc said:

can any advice that once i configure map drive through login script i am not able to access map drive getting access denied msg

# September 4, 2007 9:57 AM

Adam D said:

Can anyone tell me if there is a way of renaming the name of the drives that are mapped for example.

net use S: \\mnltegb05\server\database

will be displayed in Windows Explorer as

(S:) database on 'mnltegb05\server'

If I want the network mapping to be displayed as

(S:) Database Drive

...is there an option to do so?

thanks

# November 23, 2007 5:06 AM

Mag said:

i have my batchs file but how do i get my server to deploy it to my domain users? what i am doing for right now is i physiclly go to the computer and put the batch file in the start up items so it runs every time they restart but i would like it to run from any computer ones they type in ther user name & password?

can someone please help me

thank you

# January 2, 2008 3:54 PM

Renil said:

Can help me to create bat file for mapping network drivers?

# January 29, 2008 4:36 AM

Renil said:

Can help me to create bat file for mapping network drivers?

mail 2 me , renil.david@eds.com

# January 29, 2008 4:37 AM

Renil said:

Can help me to create bat file for mapping network drivers?

# February 21, 2008 6:25 AM

jacques said:

how do i ad a yousername and password to this line:

user: jacques

passwoed: password

net use x: \\raidmax2\share$

# March 13, 2008 3:56 AM

jacques said:

how do i create a username and password in a .bat file

username:  jacques

passwoed: password

net use x: \\raidmax2\share$

# March 13, 2008 4:32 AM

Rianne said:

I've had great success with this procedure getting new users set up on our system, however I've noticed that network drives with a space in the name do not map correctly.  Is there a quick fix for this, or will the network drives have to be renamed?

# April 9, 2008 10:30 AM

mark said:

@Rianne

you don't have to rename the network folders but the best way to overcome this I found is to rename the "share" names to remove the spaces.

I had this issue in a recent consultancy job, luckily there were only 5 users on site so it was easier that way, now they all work perfectly.

# April 13, 2008 4:40 PM

Rick said:

I was writing a batch file to map my network drive.

It successful map the drive, but something is different here.

Example in the script:

Net use M:\\servername\IT

So, you should see your mapped drive is :

IT on 'servername'(M:)

but what I see here is:

IT on 'servername'(servername)(M:)

why the (servername) show overthere ? Pls advise.

Thanks.

# April 24, 2008 3:00 AM

Theo said:

To rename a drive:

Set oShell = CreateObject("Shell.Application")

oShell.NameSpace(mDrive).Self.Name = "My Documents"

Where mDrive is the mapped drive. E.g. F:\

# May 5, 2008 6:36 PM

owais said:

hi to all

dear i want to make a simple map drive batch file for my users which can be run for automaticly add the map network drive in my client desktop and my computer.. please help or email me on owais.lhr@gmail.com

thanks waiting for your reply.

# September 19, 2008 7:56 AM

Jamie said:

Guys anyway to auto config the users exchange server each time they logon to a new machine?

i.e. not have to input exchange server mailbox and press check name....the point been to link the mailbox to that account?

I have seen this done but can't work out how to do it

# October 20, 2008 6:09 PM

Wijaya said:

How to access the password protected network folder using the batch file?

# November 18, 2008 11:49 PM

fuker ms said:

in sbs server you don need to do a batch file, in AD, on properties of user o can map a drive on logon there, then you give permision on shares for any users

simple!!!!!!

# March 18, 2009 8:16 PM

Ben said:

thanks

# August 3, 2009 7:02 AM