Jump to content

Can't query attr. "lastLogonTimestamp"


supersonic
 Share

Recommended Posts

Hello everybody,

I'm messing around with UDF "adfunctions.au3" a bit.

One of the things I'm trying to query are different attributes,

but I can't query the following:

lastLogonTimestamp

lastLogoffTimestamp

DSQUERY (part of the MS Windows Server 2003 Res. Kit) can read them.

Anyone any ideas?

Greets,

-supersonic.

Link to comment
Share on other sites

Hello everybody,

I'm messing around with UDF "adfunctions.au3" a bit.

One of the things I'm trying to query are different attributes,

but I can't query the following:

lastLogonTimestamp

lastLogoffTimestamp

DSQUERY (part of the MS Windows Server 2003 Res. Kit) can read them.

Anyone any ideas?

Greets,

-supersonic.

I just googled other uses of that, and I see things like this VBS code:
set objLogon = objUser.Get("lastLogonTimeStamp")
   set objLogon = objUser.Get("lastLogon")
   intLogonTime = objLogon.HighPart * (2^32) + objLogon.LowPart
   intLogonTime = intLogonTime / (60 * 10000000)
   intLogonTime = intLogonTime / 1440
   intLLTS = intLogonTime + #1/1/1601#
   strDays = strWeeks * 7
   intReqCompare = Now - strDays

Looks to me like it gets an object back, which has two 32-bit parts (.HighPart and .LowPart) that are assembled into a 64-bit integer for time formatting. Does you script to anything like that with the return (you didn't post any code)?

:)

P.S. Another good VBS example with an interesting explanation in the header:

' ----------------------------------------------------------------------

' Copyright © 2007 Richard L. Mueller

' Hilltop Lab web site - http://www.rlmueller.net

' Version 1.0 - March 24, 2007

' Version 1.1 - July 6, 2007 - Modify how IADsLargeInteger interface

' is invoked.

'

' The lastLogonTimeStamp attribute is Integer8, a 64-bit number

' representing the date as the number of 100 nanosecond intervals since

' 12:00 am January 1, 1601. This value is converted to a date. The last

' logon date is in UTC (Coordinated Univeral Time). It must be adjusted

' by the Time Zone bias in the machine registry to convert to local

' time.

'

' You have a royalty-free right to use, modify, reproduce, and

' distribute this script file in any way you find useful, provided that

' you agree that the copyright owner above has no warranty, obligations,

' or liability for such use.

>_< Edited by PsaltyDS
Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

Hmm... I'm not very good in porting code (from VBS to AU3)...

Of course, here's my code (I'm trying to fill a listView):

#include <Array.au3>
#include <ButtonConstants.au3>
#include <GUIConstants.au3>
#include <GUIListView.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
; <...>
#include "include\adfunctions_314.au3"
#include "include\_XMLDomWrapper.au3"


Global $lvString
Global $xmlFile
; <...>
Global $mainGUI = GUICreate("TEST", 994, 675, -1, -1)
Global $mainP   = GUICtrlCreatePic("test.bmp", 1, 1, 992, 50)
Global $mainLV  = GUICtrlCreateListView("", 1, 53, 992, 493, $LVS_SORTASCENDING, BitOR($LVS_EX_FULLROWSELECT, $LVS_EX_GRIDLINES))
Global $mainG1  = GUICtrlCreateGroup("", 001, 542, 992, 051)
Global $mainG2  = GUICtrlCreateGroup("", 001, 585, 992, 072)
Global $mainC   = GUICtrlCreateCombo("", 13, 560, 945, 21)
Global $mainB1  = GUICtrlCreateButton(">",          960, 560, 021, 021, $BS_CENTER, $WS_EX_CLIENTEDGE)
Global $mainB2  = GUICtrlCreateButton("MODIFIY",    013, 603, 100, 042, $BS_CENTER, $WS_EX_CLIENTEDGE)
Global $mainB3  = GUICtrlCreateButton("COPY",       115, 603, 100, 042, $BS_CENTER, $WS_EX_CLIENTEDGE)
Global $mainL   = GUICtrlCreateLabel("TEST", 1, 659, 992, 15, $SS_CENTER)
; <...>
GUICtrlSetBkColor($mainL, 0x484848)
GUICtrlSetBkColor($mainLV, $GUI_BKCOLOR_LV_ALTERNATE)
GUICtrlSetColor($mainL, 0xFFFFFF)
GUICtrlSetFont($mainL, 8.5, 400)
GUISetState(@SW_SHOW, $mainGUI)


$xmlFile    = _XMLFileOpen(@ScriptDir & "\test.xml")


_ou()


While 1
    $msg = GUIGetMsg()
    Select
        Case $msg = $GUI_EVENT_CLOSE
            ExitLoop
        Case $msg = $mainB1
            _ADQueryUser()
        Case $msg = $mainB2
        Case $msg = $mainB3
    EndSelect
WEnd


Func _ADQueryUser()
    If GUICtrlRead($mainC, 0) <> "" Then
        _lv()
        ; <...>
        Local $ADQueryAttributes = StringSplit($lvString, ",", 0)
        Local $ADQueryUser
        _ADGetObjectsInOU($ADQueryUser, GUICtrlRead($mainC, 0), "(&(objectCategory=user))")
        ; <...>
        Local $ADQueryArray[UBound($ADQueryUser) - 1][UBound($ADQueryAttributes) - 1]
        Local $ADQueryString
        _GUICtrlListView_DeleteAllItems($mainLV)
        For $i = 1 to UBound($ADQueryUser) - 1 Step 1
            $ADQueryString = ""
            For $j = 1 to UBound($ADQueryAttributes) - 1 Step 1
                $ADQueryArray[$i - 1][$j - 1] = _ADGetObjectAttribute($ADQueryUser[$i], $ADQueryAttributes[$j])
                ; ConsoleWrite($ADQueryUser[$i] & "---" & $ADQueryAttributes[$j] & @CRLF)
                If $j <> UBound($ADQueryAttributes) - 1 Then
                    $ADQueryString = $ADQueryString & $ADQueryArray[$i - 1][$j - 1] & "|"
                Else
                    $ADQueryString = $ADQueryString & $ADQueryArray[$i - 1][$j - 1]
                EndIf
            Next
            ; ConsoleWrite($ADQueryString & @CRLF)
            GUICtrlCreateListViewItem($ADQueryString, $mainLV)
            GUICtrlSetBkColor(-1, 0xF0F0F0)
            For $j = 0 to UBound($ADQueryAttributes) - 1 Step 1
                _GUICtrlListView_JustifyColumn($mainLV, $j, 0)
                _GUICtrlListView_SetColumnWidth($mainLV, $j, $LVSCW_AUTOSIZE)
            Next
        Next
    Else
        ; <...>
    EndIf
EndFunc


Func _lv()
    $lvArray = _XMLGetChildNodes("/ROOT/ADQuery/attributes")
    For $i = 1 to UBound($lvArray) - 1 Step 1
        $lvDummyAN = _XMLGetValue("/ROOT/ADQuery/attributes/" & $lvArray[$i])
        $lvDummyCN = _XMLGetValue("/ROOT/ADQuery/attributes/" & $lvArray[$i] & "/ColumnName")
        If $lvDummyAN[1] = "1" Then
            If $i <> UBound($lvArray) - 1 Then
                _GUICtrlListView_AddColumn($mainLV, $lvDummyCN[1])
                $lvString = $lvString & $lvArray[$i] & ","
            Else
                _GUICtrlListView_AddColumn($mainLV, $lvDummyCN[1])
                $lvString = $lvString & $lvArray[$i]
            EndIf
        Else
            ; <...>
        EndIf
    Next
EndFunc


Func _ou()
    $ou = _XMLGetValue("/ROOT/ADQuery/ou/Item")
    For $i = 1 to UBound($ou) - 1 Step 1
        GUICtrlSetData($mainC, $ou[$i], "")
    Next
EndFunc

I just googled other uses of that, and I see things like this VBS code:

set objLogon = objUser.Get("lastLogonTimeStamp")
   set objLogon = objUser.Get("lastLogon")
   intLogonTime = objLogon.HighPart * (2^32) + objLogon.LowPart
   intLogonTime = intLogonTime / (60 * 10000000)
   intLogonTime = intLogonTime / 1440
   intLLTS = intLogonTime + #1/1/1601#
   strDays = strWeeks * 7
   intReqCompare = Now - strDays

Looks to me like it gets an object back, which has two 32-bit parts (.HighPart and .LowPart) that are assembled into a 64-bit integer for time formatting. Does you script to anything like that with the return (you didn't post any code)?

:)

P.S. Another good VBS example with an interesting explanation in the header:

>_<

Link to comment
Share on other sites

Hmm... I'm not very good in porting code (from VBS to AU3)...

Of course, here's my code (I'm trying to fill a listView):

CODE
#include <Array.au3>

#include <ButtonConstants.au3>

#include <GUIConstants.au3>

#include <GUIListView.au3>

#include <StaticConstants.au3>

#include <WindowsConstants.au3>

; <...>

#include "include\adfunctions_314.au3"

#include "include\_XMLDomWrapper.au3"

Global $lvString

Global $xmlFile

; <...>

Global $mainGUI = GUICreate("TEST", 994, 675, -1, -1)

Global $mainP = GUICtrlCreatePic("test.bmp", 1, 1, 992, 50)

Global $mainLV = GUICtrlCreateListView("", 1, 53, 992, 493, $LVS_SORTASCENDING, BitOR($LVS_EX_FULLROWSELECT, $LVS_EX_GRIDLINES))

Global $mainG1 = GUICtrlCreateGroup("", 001, 542, 992, 051)

Global $mainG2 = GUICtrlCreateGroup("", 001, 585, 992, 072)

Global $mainC = GUICtrlCreateCombo("", 13, 560, 945, 21)

Global $mainB1 = GUICtrlCreateButton(">", 960, 560, 021, 021, $BS_CENTER, $WS_EX_CLIENTEDGE)

Global $mainB2 = GUICtrlCreateButton("MODIFIY", 013, 603, 100, 042, $BS_CENTER, $WS_EX_CLIENTEDGE)

Global $mainB3 = GUICtrlCreateButton("COPY", 115, 603, 100, 042, $BS_CENTER, $WS_EX_CLIENTEDGE)

Global $mainL = GUICtrlCreateLabel("TEST", 1, 659, 992, 15, $SS_CENTER)

; <...>

GUICtrlSetBkColor($mainL, 0x484848)

GUICtrlSetBkColor($mainLV, $GUI_BKCOLOR_LV_ALTERNATE)

GUICtrlSetColor($mainL, 0xFFFFFF)

GUICtrlSetFont($mainL, 8.5, 400)

GUISetState(@SW_SHOW, $mainGUI)

$xmlFile = _XMLFileOpen(@ScriptDir & "\test.xml")

_ou()

While 1

$msg = GUIGetMsg()

Select

Case $msg = $GUI_EVENT_CLOSE

ExitLoop

Case $msg = $mainB1

_ADQueryUser()

Case $msg = $mainB2

Case $msg = $mainB3

EndSelect

WEnd

Func _ADQueryUser()

If GUICtrlRead($mainC, 0) <> "" Then

_lv()

; <...>

Local $ADQueryAttributes = StringSplit($lvString, ",", 0)

Local $ADQueryUser

_ADGetObjectsInOU($ADQueryUser, GUICtrlRead($mainC, 0), "(&(objectCategory=user))")

; <...>

Local $ADQueryArray[uBound($ADQueryUser) - 1][uBound($ADQueryAttributes) - 1]

Local $ADQueryString

_GUICtrlListView_DeleteAllItems($mainLV)

For $i = 1 to UBound($ADQueryUser) - 1 Step 1

$ADQueryString = ""

For $j = 1 to UBound($ADQueryAttributes) - 1 Step 1

$ADQueryArray[$i - 1][$j - 1] = _ADGetObjectAttribute($ADQueryUser[$i], $ADQueryAttributes[$j])

; ConsoleWrite($ADQueryUser[$i] & "---" & $ADQueryAttributes[$j] & @CRLF)

If $j <> UBound($ADQueryAttributes) - 1 Then

$ADQueryString = $ADQueryString & $ADQueryArray[$i - 1][$j - 1] & "|"

Else

$ADQueryString = $ADQueryString & $ADQueryArray[$i - 1][$j - 1]

EndIf

Next

; ConsoleWrite($ADQueryString & @CRLF)

GUICtrlCreateListViewItem($ADQueryString, $mainLV)

GUICtrlSetBkColor(-1, 0xF0F0F0)

For $j = 0 to UBound($ADQueryAttributes) - 1 Step 1

_GUICtrlListView_JustifyColumn($mainLV, $j, 0)

_GUICtrlListView_SetColumnWidth($mainLV, $j, $LVSCW_AUTOSIZE)

Next

Next

Else

; <...>

EndIf

EndFunc

Func _lv()

$lvArray = _XMLGetChildNodes("/ROOT/ADQuery/attributes")

For $i = 1 to UBound($lvArray) - 1 Step 1

$lvDummyAN = _XMLGetValue("/ROOT/ADQuery/attributes/" & $lvArray[$i])

$lvDummyCN = _XMLGetValue("/ROOT/ADQuery/attributes/" & $lvArray[$i] & "/ColumnName")

If $lvDummyAN[1] = "1" Then

If $i <> UBound($lvArray) - 1 Then

_GUICtrlListView_AddColumn($mainLV, $lvDummyCN[1])

$lvString = $lvString & $lvArray[$i] & ","

Else

_GUICtrlListView_AddColumn($mainLV, $lvDummyCN[1])

$lvString = $lvString & $lvArray[$i]

EndIf

Else

; <...>

EndIf

Next

EndFunc

Func _ou()

$ou = _XMLGetValue("/ROOT/ADQuery/ou/Item")

For $i = 1 to UBound($ou) - 1 Step 1

GUICtrlSetData($mainC, $ou[$i], "")

Next

EndFunc

Well, all the GUI and listview stuff is a useless distraction. How about coding a single query of a single user with the simplest results display possible?

Since you are just enumerating all attributes without any processing at all, which of the attributes you get is "LastLogonTime"? And how do you know what you ARE getting for that (perhaps VarGetType() on the returned value)?

:)

Edited by PsaltyDS
Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

Well, all the GUI and listview stuff is a useless distraction. How about coding a single query of a single user with the simplest results display possible?

Since you are just enumerating all attributes without any processing at all, which of the attributes you get is "LastLogonTime"? And how do you know what you ARE getting for that (perhaps VarGetType() on the returned value)?

:)

The GUI/LV stuff will be filled with results from _ADGetObjectsInOU/_ADGetObjectAttribute (= user(s)/attribute(s)).

These functions are part of ADFUNCTIONS.AU3. I have already tried coding the simplest query possible. And, of course,

without any problems. Just these INTEGER8 return values won't be displayed. VarGetType() returns "0".

Edited by supersonic
Link to comment
Share on other sites

  • 2 months later...

The GUI/LV stuff will be filled with results from _ADGetObjectsInOU/_ADGetObjectAttribute (= user(s)/attribute(s)).

These functions are part of ADFUNCTIONS.AU3. I have already tried coding the simplest query possible. And, of course,

without any problems. Just these INTEGER8 return values won't be displayed. VarGetType() returns "0".

While replying to another topic, a solution was found to dealing with 'INTEGER8' (64-bit integer) values, and lastLogon conversion to a time string in particular. See code here.

:)

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
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

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...