hemichallenger Posted June 18, 2014 Posted June 18, 2014 Func _AD() _AD_Open() If $strAccount = Null Then MsgBox(16, "NULL", "No user currently logged on." ) ElseIf _AD_ObjectExists(StringSplit($strAccount, '\', $STR_ENTIRESPLIT)[2]) Then $aProperties = _AD_GetObjectProperties(StringSplit($strAccount, '\', $STR_ENTIRESPLIT)[2], "lastLogon,telephoneNumber") GUICtrlSetData($Output, "Username : "& StringSplit($strAccount, '\', $STR_ENTIRESPLIT)[2] & @CRLF & _ "Last Logon Time : "& $aProperties[1][1]& @CRLF & _ "Telephone number : "& $aProperties[2][1]) _AD_Close() Else GUICtrlSetData($Output, "Username : "& StringSplit($strAccount, '\', $STR_ENTIRESPLIT)[2] & @CRLF & _ "Account name " & StringSplit($strAccount, '\', $STR_ENTIRESPLIT)[2] & " not in AD") EndIf EndFunc Maybe someone could point me in the right direction in how to fix this issue. Just having issues with accounts that have empty fields in AD like for example telephoneNumber. "Telephone number : "& $aProperties[2][1]) since im pulling information and the information aint there the script crashes. Is it possible if that field is empty to ignore that line?
javiwhite Posted June 19, 2014 Posted June 19, 2014 (edited) What's the error you're receiving? I'm assuming that its the array or subscript out of range error? If that is the case, Just nest the GUIctrlSetData in an If Statement: if uBound($aProperties,1) >= 3 then GUICtrlSetData($Output, "Username : "& StringSplit($strAccount, '\', $STR_ENTIRESPLIT)[2] & @CRLF & _ "Last Logon Time : "& $aProperties[1][1]& @CRLF & _ "Telephone number : "& $aProperties[2][1]) endif Obviously you'll need to play around with the numbers to suit your script; But from what you've provided; The above should be skipped if $aProperties[2][$x] dimension is out of range, and therefore suppress the error. EDIT: Apologies, On hindsight I've realised you probably don't want to skip all the information, Just the telephone.... In that case: if uBound($aProperties,1) >= 3 then GUICtrlSetData($Output, "Username : "& StringSplit($strAccount, '\', $STR_ENTIRESPLIT)[2] & @CRLF & _ "Last Logon Time : "& $aProperties[1][1]& @CRLF & _ "Telephone number : "& $aProperties[2][1]) else GUICtrlSetData($Output, "Username : "& StringSplit($strAccount, '\', $STR_ENTIRESPLIT)[2] & @CRLF & _ "Last Logon Time : "& $aProperties[1][1]) endif Edited June 19, 2014 by javiwhite give a man an application, and he'll be frustrated for the day, Teach him how to program applications and he'll be frustrated for a lifetime.
water Posted June 19, 2014 Posted June 19, 2014 What is the return value of _AD_GetObjectProperties and what is the value of @error and @extended? My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki
hemichallenger Posted June 20, 2014 Author Posted June 20, 2014 Func _AD() Local $strComputer = GUICtrlRead ($Input1) _AD_Open() If $strAccount = Null Then GUICtrlSetData($Output, "No user currently logged on to " & @CRLF & _ $strComputer & ".") ElseIf _AD_ObjectExists(StringSplit($strAccount, '\', $STR_ENTIRESPLIT)[2]) Then $adObj_telephoneNumber = _AD_GetObjectProperties(StringSplit($strAccount, '\', $STR_ENTIRESPLIT)[2], 'telephoneNumber') If $adObj_telephoneNumber[0][0] <> 0 Then $adObj_telephoneNumber = $adObj_telephoneNumber[1][1] $adObj_LastLogon = _AD_GetObjectProperties(StringSplit($strAccount, '\', $STR_ENTIRESPLIT)[2], 'lastLogon') If $adObj_LastLogon[0][0] <> 0 Then $adObj_LastLogon = $adObj_LastLogon[1][1] GUICtrlSetData($Output, "Username : "& StringSplit($strAccount, '\', $STR_ENTIRESPLIT)[2] & @CRLF & _ "Last Logon Time : "& $adObj_LastLogon & @CRLF & _ "Telephone number : "& $adObj_telephoneNumber) _AD_Close() Else GUICtrlSetData($Output, "Username : "& StringSplit($strAccount, '\', $STR_ENTIRESPLIT)[2] & @CRLF & _ "Account name " & StringSplit($strAccount, '\', $STR_ENTIRESPLIT)[2] & " does not exist in AD.") EndIf EndFunc I got it to work. Thanks guys for replying,
water Posted June 20, 2014 Posted June 20, 2014 My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki
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