VBScript version
To determine if the user is a member of a group, we will assume there is an Active Directory
and use the LDAP provider, as this will require the least number of lines.
If IsMember("SalesStaff") Then MapNetworkDrive "I:","\\AcmeServer\Sales"
Function IsMember(groupName)
Const ADS_NAME_INITTYPE_GC = 3
Const ADS_NAME_TYPE_NT4 = 3
Const ADS_NAME_TYPE_1779 = 1
''==== CONVERT GROUP NAME TO FULLY QUALIFIED NAME ====
Set WSHNetwork = WScript.CreateObject("WScript.Network")
Set objTrans = CreateObject("NameTranslate")
objTrans.Init ADS_NAME_INITTYPE_GC, ""
objTrans.Set ADS_NAME_TYPE_NT4, WSHNetwork.UserDomain & "\" & groupName
strGroupDN = objTrans.Get(ADS_NAME_TYPE_1779)
strGroupDN = Replace(strGroupDN, "/", "\/")
''==== GET GROUP AND USER ====
Set objGroup = GetObject("LDAP://" & strGroupDN)
Set objADSysInfo = CreateObject("ADSystemInfo")
strUserDN = objADSysInfo.UserName
''==== DETERMINE MEMBERSHIP ====
If objGroup.IsMember("LDAP://" & strUserDN) Then
IsMember=True
Else
IsMember=False
End If
End function
Function MapNetworkDrive(letter, uncPath)
''==== DISCONNECT EXISTING DRIVE IF CONNECTED ====
Set objNetwork = CreateObject("WScript.Network")
Set objDrives = objNetwork.EnumNetworkDrives()
For objDrive = 0 To objDrives.Count - 1 Step 2
If objDrives.Item(objDrive) = letter Then
objNetwork.RemoveNetworkDrive letter, true
End If
Next
''==== MAP SHARE ====
objNetwork.MapNetworkDrive letter, uncPath, false
End function
FastTrack Script version
Using a FastTrack Script the same operation requires just one line. In case of an error,
the general error handler script (errorhandler.fsh) will be included and the script will continue.
If UserIsMemberOf
SalesStaff Then ConnectShare
I:,\\AcmeServer\Sales
Performance note
The VBScript example will be slower and will stress your Active Directory, if there are many
computers in the network, as it will query your Active Directory over the network every time a user logs on.
The FastTrack Script version will query only against locally cached information, which the
WinLogon process has already retrieved from your domain controller.