Question

Locked

VB Script Login using dist group lookups

By plonka2000 ·
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 conversation is currently closed to new comments.

1 total post (Page 1 of 1)  
| Thread display: Collapse - | Expand +

All Answers

Collapse -

Here's how to get the user object by LDAP

by neilb@uk In reply to VB Script Login using dis ...

Const ADS_NAME_INITTYPE_GC = 3
Const ADS_NAME_TYPE_NT4 = 3
Const ADS_NAME_TYPE_1779 = 1

Dim oNet, oTrans, sUserDN, oUser

Set oNet = CreateObject("WScript.Network")
Set oTrans = CreateObject("NameTranslate")
oTrans.Init ADS_NAME_INITTYPE_GC, ""
oTrans.Set ADS_NAME_TYPE_NT4, oNet.UserDomain & "\" & oNet.UserName
sUserDN = oTrans.Get(ADS_NAME_TYPE_1779)
Set oUser = GetObject("LDAP://" & sUserDN)

The property oUser.memberof is a collection of the distinguished names of all the groups of which the user is a member. You can then put these straight into an LDAP search to get any group properties you want.

What is it that you actually want to do?

Neil :)

Back to Hardware Forum
1 total post (Page 1 of 1)  

Related Discussions

Related Forums