PDA

View Full Version : scripting to install mapped drives to users (W2K)



enyalius
03-22-2004, 08:50 AM
I am running a SBS2000 server and want to put a script on the server so that particular groups get drives assigned to them when they login to the network, each time they login it will map the drives to the same letters that I assign them. can someone give me examples on how I would do this for particular users/groups? thanks

wchull
03-30-2004, 06:00 PM
What you are asking to do is not technically hard to do but requires a certain amount of coding to get the job done.

For starters you are going have to enumerate your group and perhaps stow them in an array. Later parse through the array looking for a group name match. If the match occurs then you might consider seeing if the drive letter you are wanting to use is currently in use and whether the user has mapped a sharepoint to that drive letter persistently. If the drive letter and sharepoint matches what the user already has mapped then do nothing otherwise if the drive letter is in use, deallocate the drive and map the drive letter to a different share. Here is a bit of code that shows how to do the last step.

If ValidNetworkGDrive <> "" Then
ValidNetworkGDrive = UCase(ValidNetworkGDrive)
If ValidNetworkGDrive <> UCase(Mid(GlobalDrive,6)) Then
If InStr(GlobalDrive,"\\") then
WshNetwork.RemoveNetworkDrive "G:",bForce,bUpdateProfile
End If
WshNetwork.MapNetworkDrive "G:",ValidNetworkGDrive,bUpdateProfile
GlobalDrive = ValidNetworkGDrive
End If
End If

In the above code we know, through previous code, that this user is a member of certain group and have determined what the share point should be for ValidNetworkGDrive and have set this varible to the UNC path (i.e. \\server\share). We also know, from previous code, what UNC path, if any, is mapped to the G: drive and have set the GlobalDrive variable with this info. (Note that a presistent drive in a users profile will be mapped prior to any logon script). We then compare the contents of the two varibles together to see if they match and if they are equal we do nothing. If the G: drive is not currently allocated we map the drive presistent so the next time they log on they will be mapped to that drive. If the drive letter is in use we deallocate the share and then reallocate it. Whether you map persistenly or not is a choice you will have to make yourself.

Sorry I can't help more but this gets very involved based on whether you are an NT domain or Active Directory and if you are Active Directory whether the group you are looking for is nested inside another group.

Hope this helps.