Hello,
I have written a vbscript - actually an HTA, which checks to see if a
user is a member of an AD group. For some users it will correctly
return the correct results. For others it will say that a user is not a
member of a group when actually they are. When looking at group
membership through the Active Directory snap in it shows the correct
membership. At first I thought the issue might be something to do with
the Domain Controller the script was interrogating, however looking on
those DC's with the AD snap in also shows the correct membership. It is
worth mentioning that newer accounts dont seem to return the correct
results. The only thing that needs to be changed in the HTA is
"strNetBIOSDomain = "DOMAIN"" and replace DOMAIN with your correct
Domain name.
Here is my HTA:
<html>
<head>
<title>HTA Helpomatic</title>
<HTA:APPLICATION
ID="objHTAHelpomatic"
APPLICATIONNAME="HTAHelpomatic"
SCROLL="yes"
SINGLEINSTANCE="yes"
WINDOWSTATE="normal"
>
</head>
<SCRIPT Language="VBScript">
Sub RunScript
strGroup = group.value
strGroupText = group.value
strUser = user.value
Const ADS_NAME_INITTYPE_GC = 3
Const ADS_NAME_TYPE_NT4 = 3
Const ADS_NAME_TYPE_1779 = 1
Dim objTrans, objShell, objGroup
Set objShell = CreateObject("Wscript.Shell")
strNetBIOSDomain = "DOMAIN"
Set objTrans = CreateObject("NameTranslate")
objTrans.Init ADS_NAME_INITTYPE_GC, ""
objTrans.Set ADS_NAME_TYPE_NT4, strNetBIOSDomain & "\" & strUser
strUserDN = objTrans.Get(ADS_NAME_TYPE_1779)
objTrans.Set ADS_NAME_TYPE_NT4, strNetBIOSDomain & "\" & strGroup
strGroupDN = objTrans.Get(ADS_NAME_TYPE_1779)
'msgbox struserdn
'MsgBox strGroupDN
'MsgBox """" & "LDAP://" & strGroupDN & """"
'strGroupDN = """" & "LDAP://" & strGroupDN & """"
strGroupDN = "LDAP://" & strGroupDN
'MsgBox strGroupDN
Set objGroup = GetObject(strGroupDN)
objGroup.GetInfo
arrMemberOf = objGroup.GetEx("member")
StrCompare = struserdn
For Each strMember in arrMemberOf
intCompare = StrComp(StrCompare, strMember, vbTextCompare)
If intCompare = 0 Then
MsgBox "User is a member of the " & strGroupText & "
group",,"Group Information"
Exit For
End if
Next
If intCompare <> 0 Then
MsgBox "User is not a member of the " & strGroupText & " group",,"Group
Information"
End If
End sub
</SCRIPT>
<body>
<font color="red">
<face ="Times New Roman">
<H1 align="center"font color="red"> Is User Member of Group </H1>
<font color="blue" face="Times New Roman" size="4">User
<input type="text" name="User" size="25">
<font color="blue" face="Times New Roman" size="4">Group
<input type="text" name="Group" size="25">
<br>
<br>
<input id=runbutton class="button" type="button" value="Get Info"
name="run_button" onClick="RunScript">
</body>
</html>
Many thanks for any assistance,
Ben