VB6 - koden er magen til den der er i den artikel du henviste til:
Private Function VerifyAccess(strUser As String, strPassword As String, strGroup As String) As Boolean
On Error Resume Next
Dim strDnsDomain As String
Dim strDomains() As String
Dim i As Integer
Dim hKey As Long
Dim strUserUPN As String
Dim objUser As IADsUser
Dim objDsOpenObject As IADsOpenDSObject
Dim objGroup As IADsGroup
strUserUPN = "CN=" & strUser & ",CN=Users"
RegOpenKeyEx HKEY_LOCAL_MACHINE, "SYSTEM\CurrentControlSet\Services\TcpIp\Parameters", 0&, KEY_QUERY_VALUE, hKey
strDnsDomain = Space(255)
RegQueryValueEx hKey, "Domain", 0&, REG_SZ, ByVal strDnsDomain, Len(strDnsDomain)
RegCloseKey hKey
'This gets the domain from registry settings on user machine
strDnsDomain = "." & Left(strDnsDomain, InStr(strDnsDomain, Chr(0)) - 1)
strDomains = Split(strDnsDomain, ".")
For i = 1 To UBound(strDomains)
strUserUPN = strUserUPN & ",DC=" & strDomains(i)
Next i
Set objDsOpenObject = GetObject("LDAP:")
If Len(strPassword) Then
'Log on to AD as the specified user and retrieve all user information
'--> denne fejler altid, dvs. objUser er altid nothing!
Set objUser = objDsOpenObject.OpenDSObject("
LDAP://" & strUserUPN, strUserUPN, strPassword, ADS_SECURE_AUTHENTICATION)
Else
'No password, so just use anonymous bind...
Set objUser = GetObject("
LDAP://" & strUserUPN)
End If
'Return failure if user not found (or logon credentials rejected)
If Len(objUser.Guid) = 0 Then Exit Function
'Now, enumerate all groups the user is in
For Each objGroup In objUser.Groups
If LCase(objGroup.Name) = "cn=" & LCase(strGroup) Then
VerifyAccess = True
Exit For
End If
Next
End Function