jtrout Posted June 28, 2007 Share Posted June 28, 2007 CODE dim cn ' as ADOB.Connection dim iDobj ' as IADs Dim o ' as object Dim strSvr ' as string Dim strLDAP ' as string Dim strCred ' as string dim strUser ' as string dim strPW ' as string Dim strSearch ' as string Dim i ' as integer Dim iSecurity ' as integer Const ADS_CLEARTEXT = 0 Const ADS_SECURE_AUTHENTICATION = &h1 Const ADS_USE_ENCRYPTION = &h2 Const ADS_USE_SSL = &h2 Const ADS_READONLY_SERVER = &h4 Const ADS_PROMPT_CREDENTIALS = &h8 Const ADS_NO_AUTHENTICATION = &h10 Const ADS_FAST_BIND = &h20 Const ADS_USE_SIGNING = &h40 Const ADS_USE_SEALING = &h80 Const ADS_USE_DELEGATION = &h100 Const ADS_SERVER_BIND = &h200 Const ADS_NO_REFERRAL_CHASING = &h400 Const ADS_AUTH_RESERVED = &h80000000 Dim strSvrPort ' as string Const PORT_DEFAULT = "" Const PORT_CLEARTEXT = ":888" Const PORT_SECURE = ":999" on error resume next strUser = InputBox("Enter your Username:") strPW = InputBox("Enter your Password:") strCred = "cn=" & strUser & ",ou=people,dc=company,dc=net" set cn = GetObject("LDAP:") iSecurity = ADS_CLEARTEXT strSvrPort = PORT_CLEARTEXT strSvr = "server.company.net" strLDAP = "LDAP://" & strSvr & strSvrPort & "/cn=" & strUser & ",ou=people,dc=company,dc=net" set iDObj = cn.OpenDSObject( strLDAP, strCred, strPW, iSecurity) If (iDObj.Class = "inetOrgPerson") Then WScript.Echo "mail " & iDObj.mail Else i = 0 WScript.Echo iDObj.Class & ": " & iDObj.name WScript.Echo "... contains ..." For Each o In iDObj WScript.Echo o.Class & ": " & o.name i=i+1 If (i>10) Then WScript.Echo "etc..." Exit For End If Next End If This bring me back information but what I really need is just part of this program in auoit so that I can make sure that the connection is successful to test the User Id and Password for authentication before continue on with my script. Can anyone help? Link to comment Share on other sites More sharing options...
jtrout Posted June 29, 2007 Author Share Posted June 29, 2007 (edited) CODE Dim $cn ; as ADOB.Connection Dim $iDobj ; as IADs Dim $o ; as object Dim $strSvr ; as string Dim $strLDAP ; as string Dim $strCred ; as string dim $strUser ; as string dim $strPW ; as string Dim $strSearch ; as string Dim $i ; as integer Dim $iSecurity ; as integer Const $ADS_CLEARTEXT = "0" Const $ADS_SECURE_AUTHENTICATION = "&h1" Const $ADS_USE_ENCRYPTION = "&h2" Const $ADS_USE_SSL = "&h2" Const $ADS_READONLY_SERVER = "&h4" Const $ADS_PROMPT_CREDENTIALS = "&h8" Const $ADS_NO_AUTHENTICATION = "&h10" Const $ADS_FAST_BIND = "&h20" Const $ADS_USE_SIGNING = "&h40" Const $ADS_USE_SEALING = "&h80" Const $ADS_USE_DELEGATION = "&h100" Const $ADS_SERVER_BIND = "&h200" Const $ADS_NO_REFERRAL_CHASING = "&h400" Const $ADS_AUTH_RESERVED = "&h80000000" Dim $strSvrPort ; as string Const $PORT_DEFAULT = "" Const $PORT_CLEARTEXT = ":888" Const $PORT_SECURE = ":999" $strUser = InputBox("SID","Enter your Username (X123456):") $strPW = InputBox("Password","Enter your Password:", "", "*") $strSearch = $strUser $strCred = "cn=" & $strUser & ",ou=ou,dc=mycompany,dc=com" $cn = ObjGet("LDAP:") $iSecurity = $ADS_CLEARTEXT $strSvrPort = $PORT_CLEARTEXT $strSvr = "myserver.mycompany.com" $strLDAP = "LDAP://" & $strSvr & $strSvrPort & "/cn=" & $strSearch & ",ou=ou,dc=mycompany,dc=com" $iDobj = $cn.OpenDSObject( $strLDAP, $strCred, $strPW, $iSecurity) If @error <> 0 Then MsgBox(0,"ERROR", "FAILED for some reason") EndIf If ($iDobj.Class = "inetOrgPerson") Then ; ----- Short Form ----- If $iDobj.uid = $strSearch Then MsgBox(0,"Success","We matched and tested the password") Else MsgBox(0,"Error","Something is off in the weeds") EndIf Else MsgBox(0,"Error","Did not establish a connection") MsgBox(0,"Error","Something is off in the weeds") ; ----- DrillDown ----- $i = 0 MsgBox(0,"",$iDobj.Class & ": " & $iDobj.name) MsgBox(0,"","... contains ...") For $o In $iDobj MsgBox(0,"",$o.Class & ": " & $o.name) $i=$i+1 If ($i>10) Then MsgBox(0,"","etc...") ExitLoop EndIf Next EndIf OK. All works well when the User logs in correctly but when I messup and don't use the correct Username or Password it fails on $iDobj = $cn.OpenDSObject( $strLDAP, $strCred, $strPW, $iSecurity) which is good but I need to caputure the failure and give a message exit gracefully. Can anyone help me with that? This is the error that is given in the output "The requested action with this object has failed.: " $iDobj = $cn.OpenDSObject( $strLDAP, $strCred, $strPW, 1) $iDobj = $cn.OpenDSObject( $strLDAP, $strCred, $strPW, 1)^ ERROR ->10:58:38 AutoIT3.exe ended.rc:1 Edited June 29, 2007 by jtrout Link to comment Share on other sites More sharing options...
jtrout Posted June 29, 2007 Author Share Posted June 29, 2007 CODE Dim $cn ; as ADOB.Connection Dim $iDobj ; as IADs Dim $strSvr ; as string Dim $strLDAP ; as string Dim $strCred ; as string Dim $strUser ; as string Dim $strPW ; as string Dim $iSecurity ; as integer Dim $strSvrPort ; as string Const $ADS_SECURE_AUTHENTICATION = "&h1" Const $ADS_SERVER_BIND = "&h200" Const $PORT_CLEARTEXT = ":888" $strUser = InputBox("SID", "Enter your Username:") $strPW = InputBox("Password", "Enter your Password:", "", "*") $strCred = "cn=" & $strUser & ",ou=ou,dc=mycompany,dc=com" $oMyError = ObjEvent("AutoIt.Error","MyErrFunc") ; Install a custom error handler $cn = ObjGet("LDAP:") $iSecurity = $ADS_SECURE_AUTHENTICATION + $ADS_SERVER_BIND $strSvrPort = $PORT_CLEARTEXT $strSvr = "server.mycompany.com" $strLDAP = "LDAP://" & $strSvr & $strSvrPort & "/cn=" & $strUser & ",ou=ou,dc=mycompany,dc=com" $iDobj = $cn.OpenDSObject ($strLDAP, $strCred, $strPW, $iSecurity) If @error = 1 Then MsgBox(0, "ERROR", "Invalid Username/Password.") Exit EndIf Func MyErrFunc() $HexNumber=hex($oMyError.number,8) ;~ Msgbox(0,"","We intercepted a COM Error !" & @CRLF & _ ;~ "Number is: " & $HexNumber & @CRLF & _ ;~ "Windescription is: " & $oMyError.windescription ) SetError(1) ; something to check for when this function returns Endfunc Final version works after adding custom error handler. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now