SBS 2003 assigning mapped drives?

Heeter

Overclocked Like A Mother
Joined
8 Jul 2002
Messages
2,732
Hey All,

Was wondering if I can setup SBS2003 to assign mapped drives to workstations instead of me going around manually mapping them from each workstation?


Thanks,

Heeter
 
use a login script, assign the login script to the user accounts
 
Thanks Fitz,

would you know of a copy that I can find of this logon script that I could use as a template?

Since it is a script, I am presuming that it is a .bat file, am I correct?


Thanks,

Heeter
 
you can use either batch or VBScript/WSH (windows Script Host) - technically, you can also use KIX and some other ones too..

in Batch:
net use <drive letter> <share path>
Code:
net use z: \\server1\shareMe

in VBScript
Code:
set objNet = CreateObject("wscript.Network")
objNet.MapNetworkDrive "z:","\\server1\shareMe"

Note: neither of these does much error checking.. for example, if the drive letter is already mapped, it will fail. You can put in some error checking etc and remap drives if needed.

Since I prefer VBScript, you can copy my script below and hack it up for your needs. It does some minor error checking..
Code:
set objNet = CreateObject("Wscript.Network")
set objFSO = CreateObject("Scripting.FileSystemObject")

strPath = "\\server1\shareName"
strDriveLetter = "z:"

'checks to see if the drive letter is already mapped
if not ( objFSO.DriveExists(strDriveLetter) ) then 

    'drive is not mapped, so just map the drive and we're done
    objNet.MapNetworkDrive strDriveLetter,strPath

else    

    'if the drive is already mapped, check to see if it is mapped to the correct share
    'if the drive is mapped correctly, nothing to do
    'if the drive is mapped to a different share, disconnect the share and map correctly
    set objDrive = objFSO.GetDrive(strDriveLetter)
    if not (objDrive.ShareName = strPath) then
        objNet.RemoveNetworkDrive strDriveLetter,true,true
        objNet.MapNetworkDrive strDriveLetter,strPath
    end if
end if
The scripts will go into the netlogon share of the domain controller (in this case your SBS server). Going into ADUC (Active Directory Users and Computers) you can assign the script under the profile tab in the user account properties. Technically, you can also use a GPO to assign a login script.


edit: and madmatt.. piss off and stop bugging me in IM to post a script :) :p
 
Just making sure you fulfill your duties as a moderator and master scripter. =)
 
Awesome, thanks for the template!!!!!!


Should I go around and disconnect the existing mapped drives?

With this setup, I will presume that I can create a different vbscript for each drive that I would like to map, would this be correct?

saving this file would be *.vbs, like in my situation it would be datadrive.vbs and specdrive.vbs, etc, etc?


Thanks again for all your help.



Heeter
 
Awesome, thanks for the template!!!!!!

Should I go around and disconnect the existing mapped drives?
well, I like to do it to make sure my users are all connected to the correct drives as some of them got into the habit of remapping drives. The script snippet I wrote will automagically disconnect the drive if the drive letter that you are trying to map correctly is in use.

With this setup, I will presume that I can create a different vbscript for each drive that I would like to map, would this be correct?

saving this file would be *.vbs, like in my situation it would be datadrive.vbs and specdrive.vbs, etc, etc?
funny.. madmatt asked me the same question in an IM..

basically, no - you don't create seperate scripts for each drive. The user account properties will only accept a single login script file (although, technically I suppose you could create seperate vbs files and call them through a bat file and have the bat file as your one login script.

But, generally, you'll wrap it into one file. You could remove the variables (strDriveLetter and strPath) and use the actual string values and write multiple connect lines like:
Code:
objNetwork.MapNetworkDrive "y:","\\server\share1"
objNetwork.MapNetworkDrive "z:","\\server\share2"
.
.
.
But you would have to wrap the lines to check each drive letter and disconnect the existing drive for each path if you wanted that functionality.

A better way would be to turn the mapping script section into a function/subroutine and call the function from the main script. Something along the lines of this:

Code:
MapDrive "x:","\\192.168.25.103\c$"
MapDrive "y:","\\192.168.25.103\e$"
wscript.quit

Function MapDrive(strDriveLetter,strPath)
  set objNet = CreateObject("Wscript.Network")
  set objFSO = CreateObject("Scripting.FileSystemObject")

  if not ( objFSO.DriveExists(strDriveLetter) ) then 
     objNet.MapNetworkDrive strDriveLetter,strPath
  else    
     set objDrive = objFSO.GetDrive(strDriveLetter)
     if not (objDrive.ShareName = strPath) then
        objNet.RemoveNetworkDrive strDriveLetter,true,true
        objNet.MapNetworkDrive strDriveLetter,strPath
     end if
  end if
End Function


Thanks for lighting a fire under his butt, Matt, LOLOL

yeah.. I think he called me lazy or something along those lines asking why I didn't just post the script. I havea copy of the IM conversation somewhere on my work laptop (working on my home machine now).
 
Last edited:
Thanks again, for your input and time.

I am going to be making the mods to the SBS2003 Domain Controller in the morning, and I am certainly going to use that last one you posted. Everyone is going to see the same two drives:

So it should look like this:

Code:
MapDrive "M:","\\server\D:\Data$"
MapDrive "N:","\\server\D:\Spec$"
wscript.quit

Function MapDrive(strDriveLetter,strPath)
  set objNet = CreateObject("Wscript.Network")
  set objFSO = CreateObject("Scripting.FileSystemObject")

  if not ( objFSO.DriveExists(strDriveLetter) ) then 
     objNet.MapNetworkDrive strDriveLetter,strPath
  else    
     set objDrive = objFSO.GetDrive(strDriveLetter)
     if not (objDrive.ShareName = strPath) then
        objNet.RemoveNetworkDrive strDriveLetter,true,true
        objNet.MapNetworkDrive strDriveLetter,strPath
     end if
  end if

End Function

I am going to save it as "mapped.vbs"

I won't bother with going around and disconnecting the M: mapped drives already there.

How does this look to you?


I can't thank you enough for your time....



Heeter
 
Thanks again, for your input and time.
no worries
I am going to be making the mods to the SBS2003 Domain Controller in the morning, and I am certainly going to use that last one you posted.
Make sure you remember to add the script to the user account so they actually run the script when they login.
Code:
MapDrive "M:","\\server\D:\Data$"
MapDrive "N:","\\server\D:\Spec$"
wscript.quit
[/quote]
I'm not sure if \\server\d:\data$ is a valid share name.. you may want to test that before hand and make sure you are using the correct share path.

[quote]I won't bother with going around and disconnecting the M: mapped drives already there.
[/quote]
As I mentioned, the script code I wrote will check and disconnect an M: drive already if it is not mapped to the correct share. The script it self will do it so you don't have to do it yourself physically. :)
 
Update,

Thanks Fitz,

I still haven't quite figured out the filepath for the shared drives on the network, but it is something that I will continue to play with as I go along. Right now, it is disconnecting the manually mapped drive when the user logs on, but not issuing the vbs mapped drives.

I erased the default .bat file that was in the logon script section of the profile. But I was wondering if I could of just added the vbs script to the original line, sort of like this into the logon script line of the profile:

Code:
logonscript.bat; mappeddrive.vbs

I don't know if this works or not, can't really see the difference.


Heeter
 
This is pretty darn cool - when I first read this thread I remember thinking " why do you need error checking for a login script?" But, this actually will override anything they have done locally? Such as....

login script says

net use m: \\contoso1\mattspr0n

Physical Drive mapping (done manually says)

m drive is mapped to \\contoso1\mattschildhoodphotos

So regardless, Matt's pr0n will always be mapped to M?

How would you go about addressing login scripts that don't seem to run when the person is working from home? Obviously they don't hit the PDC when logging into their machines using cached credentials, and after connecting to the VPN can only access drives that were mapped from a previous session.
 
So regardless, Matt's pr0n will always be mapped to M?

How would you go about addressing login scripts that don't seem to run when the person is working from home? Obviously they don't hit the PDC when logging into their machines using cached credentials, and after connecting to the VPN can only access drives that were mapped from a previous session.

yup.. the M: drive would also map correctly.

as for VPN, it may depend on what VPN Client is being used.. most clients have some option to run a script after login (in which case, see if it will handle vbs scripts or just wrap the vbs script in a batch file).

The bigger question on VPN logins is how to get any login script to run at all if they already logged in via Cached credentials.. connecting via VPN using the "login using dial-up" checkbox on the main GINA is a different story..

If your VPN client supports it, it may be possible to run a post-login/post connection script off the VPN client which might require the script be local on the machine.. and if it won't support vbs would require a BAT file wrapper.. the harder part on that is making sure the local script is updated when changes to the main script changes.

edit:
you could also write a local process/service that installs on the client to either watch for VPN connections and/or monitors IP changes and runs the login script that way.

It's the same issues as when a laptop user can start a computer off the network and later plug in and/or dock the laptop - no login scripts. Or if a computer's network cable is unplugged at startup and after logging in with cached credentials, they plug in the network cable..
 
Update:
I am still having issues with my mapped drive vbscript. It is disconnecting the existing M drive, but it is giving me errors, please see screenie.

Folder to map is on E:: drive (E:/ClientData), would like to call it M: drive

Thanks,

Heeter
 

Attachments

  • mapped.JPG
    mapped.JPG
    58.6 KB · Views: 629
I'm assuming if it can't find the path from the computer that is trying to run it, the user who is running the script might not have access to that admministrative share?
 
All the users that I have applied this script to in their profile have this error come up.

The folder in question has full admin/everyone privileges assigned to it.

I do manually map the drive from the workstation when I am logged in as the user. but when I relogon, the mapped M: drive gets disconnected (As the script intends it to do) and I get this error.


Heeter
 
not sure what the problem is. The error indicates that it doesn't think the share exists..

You said the m: drive gets disconnected, it should only get disconnected if the m: drive is connected to a different share (for example: the m: drive is already mapped correctly to \\1600SC\NonClientData, the script would disconnect it).
If you have the M: drive connected correctly and the script is disconnecting the drive, then you are passing the wrong share string into the script.

just for kicks, go to your start/run and just type in "\\1600SC\clientData$" (without the quotes).
 
Last edited:
Start/run, It works without the share sign

\\1600sc\clientdata$ <-doesn't work
\\1600sc\clientdata <-works


Thanks Fitz, for your help so far.........



Heeter
 
the $ is the mark to set a share as a hidden share.. if you didn't create it as a hidden share, you don't use the $ symbol.

The share path that gets passed should be the same as what you would use in the start/run (or when you map the drive any other way), so your first line of the script you are using should read:

Code:
MapDrive "M:","\\1600SC\ClientData"
 
Oh, Okay

Hidden Share, got it.

Thanks for enlightening me on this one,

Will fix up the script.

If there is two scripts that I would like to use on a user's profile, do I seperate the scripts with a ";" or just a space between them?

Thanks a million for your help, I really appreciate it.

Heeter
 

Members online

No members online now.

Latest profile posts

Also Hi EP and people. I found this place again while looking through a oooollllllldddd backup. I have filled over 10TB and was looking at my collection of antiques. Any bids on the 500Mhz Win 95 fix?
Any of the SP crew still out there?
Xie wrote on Electronic Punk's profile.
Impressed you have kept this alive this long EP! So many sites have come and gone. :(

Just did some crude math and I apparently joined almost 18yrs ago, how is that possible???
hello peeps... is been some time since i last came here.
Electronic Punk wrote on Sazar's profile.
Rest in peace my friend, been trying to find you and finally did in the worst way imaginable.

Forum statistics

Threads
62,015
Messages
673,494
Members
5,621
Latest member
naeemsafi
Back