VB Script Login using dist group lookups - TechRepublic
Question
November 24, 2010 at 03:27 AM
plonka2000

VB Script Login using dist group lookups

by plonka2000 . Updated 15 years, 7 months ago

Hi,

THis might be one for the VB Scripters among the group.

I’m using a script that I compiled some time ago to detect which group memberships a user is a member of then map the appropriate drive. The drives are mapped to DFS shares, which works but the issue I have is that the script does not see ‘Distrobution Groups’, only ‘Security Groups’.

I’m aware that this is because I need to do an LDAP lookup in the script, but I am not the best VB scripter around. Is there anyone that can help and maybe explain to me how to do this?

Here is a sample of my script for your review:

Dim WSHNetwork
Dim strUserDomain
Dim ObjGroupDict
Dim strUserName

Set WSHNetwork = WScript.CreateObject(“WScript.Network”)

strUserName = “”

While strUserName = “”

WScript.Sleep 100

strUserName = WSHNetwork.UserName

Wend

strUserDomain = WSHNetwork.UserDomain

Set ObjGroupDict = CreateMemberOfObject(strUserDomain, strUserName)

‘===========Home Directory===================

‘THIS MAPS H: TO \\mydomain\london\home\%username%

‘If MemberOf(ObjGroupDict, “Domain Users”) Then
‘ WshNetwork.MapNetworkDrive “H:”, “\\mydomain\london\home\” & WshNetwork.UserName
‘End If

‘===========Corporate Structure==============

If MemberOf(ObjGroupDict, “Domain Users”) Then
‘ WshNetwork.MapNetworkDrive “I:”, “\\mydomain\london\global”
WshNetwork.MapNetworkDrive “R:”, “\\mydomain\london\archived”
WshNetwork.MapNetworkDrive “Y:”, “\\mydomain\london\company”
End If

If MemberOf(ObjGroupDict, “Secure Admin”) Then
WshNetwork.MapNetworkDrive “U:”, “\\mydomain\london\admin”
End If

If MemberOf(ObjGroupDict, “Secure HR”) Then
WshNetwork.MapNetworkDrive “V:”, “\\mydomain\london\HR”
End If

If MemberOf(ObjGroupDict, “Secure Finance”) Then
WshNetwork.MapNetworkDrive “W:”, “\\mydomain\london\finance”
WshNetwork.MapNetworkDrive “X:”, “\\mydomain\london\finance\SageDATA”
End If

If MemberOf(ObjGroupDict, “Secure IT”) Then
WshNetwork.MapNetworkDrive “M:”, “\\mydomain\admin\IT”
WshNetwork.MapNetworkDrive “N:”, “\\mydomain\admin\Apps”
End If

‘=======================================================================

‘DO NOT EDIT THESE

‘=======================================================================

Function MemberOf(ObjDict, strKey)

MemberOf = CBool(ObjGroupDict.Exists(strKey))

End Function

Function CreateMemberOfObject(strDomain, strUserName)

Dim objUser, objGroup

Set CreateMemberOfObject = CreateObject(“Scripting.Dictionary”)

CreateMemberOfObject.CompareMode = vbTextCompare

Set objUser = GetObject(“WinNT://” _
& strDomain & “/” _
& strUserName & “,user”)

WScript.Sleep 100

For Each objGroup In objUser.Groups

CreateMemberOfObject.Add objGroup.Name, “-”

Next

Set objUser = Nothing

Set objGroup = Nothing

End Function

This discussion is locked

All Comments