Saturday, December 15, 2007

ad auth in vba

Sorry for delayed reply.

You should still be able to use the code in your first message in VB6, for example, following code works on my side in a VB6 program:

Function AuthCheck(ByVal sUser As String, ByVal sPassword As String) As Boolean
On Error GoTo E

Dim RootDSE
Dim DSObject
Dim Auth
Dim NamingContext
Const ADS_SECURE_AUTHENTICATION = 1

Set RootDSE = GetObject("GC://rootDSE")
NamingContext = RootDSE.Get("defaultNamingContext")

Set DSObject = GetObject("GC:")

Set Auth = DSObject.OpenDSObject("GC://" & NamingContext, sUser, sPassword, ADS_SECURE_AUTHENTICATION)

Set Auth = Nothing
Set DSObject = Nothing
Set RootDSE = Nothing

AuthCheck = True
Exit Function
E:
AuthCheck = False
' log the err.Description if needed
End Function


Calling AuthCheck("", "") will return True if the user/password is correct and return False if not.

If you need to use strong-typed objects, you need to reference "Active DS Type Library" in your VB6 project and use those objects accordingly. For example, OpenDSObject is a method of the interface IADsOpenDSObject.

Best regards,
Walter Wang
Microsoft Online Community Support

No comments: