Jump to content

AD UDF: lastLogon, lastLogonTimestamp results empty values


 Share

Recommended Posts

$l_ret = _AD_GetObjectAttribute(@username,"lastLogon")
MsgBox(64,"whenCreated",$l_ret & @crlf & @error)

$l_ret has no value and no error (error is 0).

Same Probleme here:

$l_user = _AD_GetObjectsInOU("OU=test,OU=example,DC=mydomain,DC=domain,DC=com","(name=*)",2,"sAMAccountName,whenCreated,lastLogon,userAccountControl","sAMAccountName")

If i displays this array sAMAccountName,whenCreated and userAccountControl have values

lastlogon values are missing...

With an LDAP Browser  i could see those values...

any ideas ??

Thanks and Regards

Martin

 

Edited by mko
Link to comment
Share on other sites

  • mko changed the title to AD UDF: lastLogon, lastLogonTimestamp results empty values

It returns an object from memory, I use the following to calculate the date from the object:

#include <AD.au3>
#include <Array.au3>
#include <Date.au3>

_AD_Open()
    Global $g_aUserAccount = _AD_GetObjectProperties(@UserName, "samaccountname,lastlogon")
    Global $g_aUserAccounts = _AD_GetObjectsInOU("", "(&(&(objectcategory=person)(objectclass=user)(samaccountname=*)))", 2, "sAMAccountName,whenCreated,lastLogon,userAccountControl","sAMAccountName")
_AD_Close()
For $i = 1 To $g_aUserAccounts[0][0]
    $g_aUserAccounts[$i][2] = _Get_LastLogonDate($g_aUserAccounts[$i][2], 1)
Next
_ArrayDisplay($g_aUserAccount)
_ArrayDisplay($g_aUserAccounts)

Func _Get_LastLogonDate($_oLastLogon, $_iLastLogon = 1)
    Local $sAD_DTStruct, $sTemp3
    If $_iLastLogon = 1 Then
        If Not IsObj($_oLastLogon) Then Return ""
        If $_oLastLogon.LowPart = -1 Then Return ""
        If $_oLastLogon.LowPart > 0 And $_oLastLogon.HighPart > 0 Then
            $sAD_DTStruct = DllStructCreate("dword low;dword high")
            DllStructSetData($sAD_DTStruct, "Low", $_oLastLogon.LowPart)
            DllStructSetData($sAD_DTStruct, "High", $_oLastLogon.HighPart)
            $sAD_Temp = _Date_Time_FileTimeToSystemTime(DllStructGetPtr($sAD_DTStruct))
            $sTemp3 = _Date_Time_SystemTimeToTzSpecificLocalTime(DllStructGetPtr($sAD_Temp))
            Return _Date_Time_SystemTimeToDateTimeStr($sTemp3, 1)
        EndIf
    EndIf
    ; Convert IADsLargeInteger parts to 100ns count
    Local $iLastLogonLow = $_oLastLogon.LowPart
    Local $iLastLogonHigh = $_oLastLogon.HighPart
    If $iLastLogonLow < 0 Then $iLastLogonHigh += 1; Compensate for IADsLargeInteger interface error
    $iLastLogon = $iLastLogonHigh * 2 ^ 32
    $iLastLogon += $iLastLogonLow

    ; Check if user ever logged in
    If $iLastLogon = 0 Then
        Return ""
    Else
        ; Convert 100ns count to integer seconds
        Local $iSeconds = Floor($iLastLogon / 10000000)
        ; Convert seconds since 12:00AM January 01, 1601 to date string
        Local $sLastLogon = _DateAdd("S", $iSeconds, "1601/01/01 00:00:00")
        ; Return result
        Return $sLastLogon
    EndIf
EndFunc

 

Edited by Subz
Link to comment
Share on other sites

Function _AD_GetObjectAttribute returns the values AS IS.
To get the attributes in a readable format use function _AD_GetObjetPÜroperties.

I just noticed that the documentation of this two functions needs to be enhanced ;)

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

 

Link to comment
Share on other sites

Thanks for your answer.

 

I cound not imagine how i should create  the $_oLastLogon object.

 

I have tried this...

_Ad_Open()

$sUser="myuser"

Local $oUser = __AD_ObjGet("LDAP://" & $sAD_HostServer & "/" & $sUser)
MsgBox(64,$sUser,_Get_LastLogonDate($oUser))

_AD_Close()

Result is 0

 

Regads

 

 

 

Link to comment
Share on other sites

Realy Great !  - I thought about it too complicated

Thanks for your help - already your first answer was correct, but I didn't read it carefully enough:(

Keypoint is to use: _Ad_GetObjectProperties instead of AD_GetObjectAttribute 

For all who stumble upon it here : If you have more then one domain controller use lastLogonTimestamp instead of lastLogon 

 

 

Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...