I am having some trouble mapping a drive based on group membership. I can successfully build a dictionary of a user's groups, but cannot derive mappings based on this. I am including the code I have:
' First test for environment
If Domain = "Testing" Then
If IsMember("Group1"
Then
wshNetwork.RemoveNetworkDrive aryDrivestoMap(9),1,1
wshNetwork.MapNetworkDrive aryDrivestoMap(9), "\\" & "Server" & "\" & arySharesToMap(9)
End If
Else
If Domain = "Production" Then
If IsMember("Group1"
Then
wshNetwork.RemoveNetworkDrive "I:"
wshNetwork.MapNetworkDrive aryDrivestoMap(9), "\\" & "Server" & "\" & arySharesToMap(9)
End If
End If
End If
wscript.echo (wshnetwork.UserDomain)
if ismember("Group1"
then
wscript.echo ("Successful"
'(THIS WORKS)
End If
WScript.Quit(0)
' *************************************************************************
'
' IsMember function to query group membership
'
' sGroup (name of the group)
'
'
Function IsMember(sGroup)
Dim AdsPath, oUser, oGroup, oGroupDict
If IsEmpty(oGroupDict) Then
Set oGroupDict = CreateObject("Scripting.Dictionary"
oGroupDict.CompareMode = vbTextCompare
AdsPath = wshNetwork.UserDomain & "/" & wshNetwork.UserName
set oUser = GetObject("WinNT://" & AdsPath & ",user"
For Each oGroup in oUser.Groups
oGroupDict.Add oGroup.Name, "."
Next
Set oUser = Nothing
End If
IsMember = CBool(oGroupDict.Exists(sGroup))
End Function
' **************************************************************************
The function seems to be working as the if IsMember(Group1) then wscript.echo("Successful"
command works. The only piece that doesn't work is the drive mapping piece.
As always, any help will be greatly appreciated!
Bill.
' First test for environment
If Domain = "Testing" Then
If IsMember("Group1"
wshNetwork.RemoveNetworkDrive aryDrivestoMap(9),1,1
wshNetwork.MapNetworkDrive aryDrivestoMap(9), "\\" & "Server" & "\" & arySharesToMap(9)
End If
Else
If Domain = "Production" Then
If IsMember("Group1"
wshNetwork.RemoveNetworkDrive "I:"
wshNetwork.MapNetworkDrive aryDrivestoMap(9), "\\" & "Server" & "\" & arySharesToMap(9)
End If
End If
End If
wscript.echo (wshnetwork.UserDomain)
if ismember("Group1"
wscript.echo ("Successful"
End If
WScript.Quit(0)
' *************************************************************************
'
' IsMember function to query group membership
'
' sGroup (name of the group)
'
'
Function IsMember(sGroup)
Dim AdsPath, oUser, oGroup, oGroupDict
If IsEmpty(oGroupDict) Then
Set oGroupDict = CreateObject("Scripting.Dictionary"
oGroupDict.CompareMode = vbTextCompare
AdsPath = wshNetwork.UserDomain & "/" & wshNetwork.UserName
set oUser = GetObject("WinNT://" & AdsPath & ",user"
For Each oGroup in oUser.Groups
oGroupDict.Add oGroup.Name, "."
Next
Set oUser = Nothing
End If
IsMember = CBool(oGroupDict.Exists(sGroup))
End Function
' **************************************************************************
The function seems to be working as the if IsMember(Group1) then wscript.echo("Successful"
As always, any help will be greatly appreciated!
Bill.