Your Windows Network Mapping won’t stay mapped?

So you went out and purchased yourself a computer to which you naively call your server. You even spent the extra $500 dollars for the latest and greatest server software Windows Server 2008r2. Woot! for you right on!

images

You went through and figured out how to create shared folders added permissions and made all that seemed fun file serving fun.

Then it hit you. I need to map all my clients which is a mix of windows XP (Home, Professional, Media Center), Vista, 7 (feel lucky no windows 2000 right?). Holy crap you have to deal with a lot of inconsistencies like how XP / Vista Home has no GPEDIT (group editor for everyone at home) or User Management. So how do you get the drives to map without a domain and without login script ability?

Lets tackle the network mapping issues first. Anyone can map a network drive while in session. However what happens when the user logs off or reboots the PC? They lose the drive mapping connections. You are asking yourself why? (You know you are. Please be still. All will be explained.) First imagine a Network of a couple of hundred Windows clients that never dropped or timed out the server connections. It would turn into a massive internal DDOS (Of course you could do network balancing and perhaps if you had the money turn your file serving into a Server farm. (Stop yelling at your screen Network and System Admins). We are talking just basics. ). As well as what if the machine is a shared resource (public for the rest of you) and mappings have to be per User on a multiuse client pc?

Typical mapping while in session is \\yourserver\nameofShare (This can go deeper and much further. However for demonstration I will stay simple.) You can also create a drive map by using map a drive from the tools menu in windows explorer. So these are simple enough however like discussed before you will drop or lose the connection when you logoff or restart given user profile. The wonderfully large Red X or Disconnected network share will show up in my computer once you login again.

How to resolve this:

All Versions of  windows: You can add a simple Registry key to run on login.

Windows Registry Editor Version 5.00

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run]
“LogonScript”=”path with options using \” to embed double quotes”
“LogoffScript”=”path with options using \” to embed double quotes”

Now you will notice that it requires a path. So where to put the script that the Registry has access.

My suggestion may not be the best but its my favorite.

“C:/Windows/Resources/login.bat”

This Path is very ambiguous to Windows. However in windows Vista and 7 you may have permission issues.

Now for what my Registry settings look like:

Windows Registry Editor Version 5.00

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run]

“Login”=”c:\\Windows\\Resources\\login.bat”
“Logout”=”c:\\Windows\\Resources\\logout.bat”

So your asking what is the login.bat and logout.bat look like?

Login.bat

REM
@echo off

net use F: /Delete > nul 2>&1
net use Q: /Delete > nul 2>&1
net use P: /Delete > nul 2>&1
net use T: /Delete > nul 2>&1
net use M: /Delete > nul 2>&1
net use R: /Delete > nul 2>&1
net use H: /Delete > nul 2>&1
net use E: /Delete > nul 2>&1
net use G: /Delete > nul 2>&1
net use I: /Delete > nul 2>&1
net use J: /Delete > nul 2>&1
net use K: /Delete > nul 2>&1

net use Q: /persistent:yes \\YourServer\Share Password /User:Name > nul 2>&1
net use P: /persistent:yes \\YourServer\Share Password /User:Name > nul 2>&1
net use M: /persistent:yes \\YourServer\Share Password /User:Name > nul 2>&1
net use T: /persistent:yes \\YourServer\Share Password /User:Name > nul 2>&1
net use F: /persistent:yes \\YourServer\Share Password /User:Name > nul 2>&1

First I clean up any old mappings and then add mappings.

Logout.bat

REM
@echo off

net use F: /Delete > nul 2>&1
net use Q: /Delete > nul 2>&1
net use P: /Delete > nul 2>&1
net use T: /Delete > nul 2>&1
net use M: /Delete > nul 2>&1
net use R: /Delete > nul 2>&1
net use H: /Delete > nul 2>&1
net use E: /Delete > nul 2>&1
net use G: /Delete > nul 2>&1
net use I: /Delete > nul 2>&1
net use J: /Delete > nul 2>&1
net use K: /Delete > nul 2>&1

This releases all mapped drives again.

So as you can see this is fairly easy to do. Now remember this is without domain and not using the user profile to map drives. So you could in future run into an issue if the scripts are not changed according to the user. IE new user with old user rights.

Download Scripts and Registry Files

Any questions please leave a comment or hit me up on twitter.

 
This entry was posted in Interesting, Networking, Windows and tagged . Bookmark the permalink.

Leave a Reply