Jump to content
Simpel

_GetLogonTime returns false

Recommended Posts

Simpel

Hi,

I wanted to use _GetLogonTime() by guinness (https://www.autoitscript.com/forum/topic/19370-autoit-wrappers/?do=findComment&comment=942069).

#include <Date.au3>
#include <Array.au3>
ConsoleWrite(_GetLogonTime() & @LF)
Func _GetLogonTime($sUserName = @UserName, $sComputerName = @ComputerName) ; Idea by trancexx: http://www.autoitscript.com/forum/topic/113611-if-isadmin-not-detected-as-admin/
    Local $aRet = DllCall("netapi32.dll", "long", "NetUserGetInfo", "wstr", $sComputerName, "wstr", $sUserName, "dword", 11, "ptr*", 0)
    _ArrayDisplay($aRet)
    If @error Or $aRet[0] Then Return SetError(1, 0, False)
    Local $sHours = DllStructGetData(DllStructCreate("ptr;ptr;ptr;ptr;dword;dword;dword;ptr;ptr;dword;dword;dword;dword;ptr;dword;ptr;dword;dword;byte;dword", $aRet[4]), 18)
    DllCall("netapi32.dll", "long", "NetApiBufferFree", "ptr", $aRet[4])
    Return _DateAdd("h", "-" & $sHours, _NowCalc())
EndFunc   ;==>_GetLogonTime

It always returns false.

I displayed $aRet:
[0]|2221
[1]|mycomputer
[2]|myuser
[3]|11
[4]|0x0000000000000000

$aRet[4] shouldn't be 0x0000000000000000 right? Any help?

Regards, Conrad

 


SciTE4AutoIt = 3.7.3.0   AutoIt = 3.3.14.2   AutoItX64 = 0   OS = Win7Pro SP1   OSArch = X64   Language = 0407/german
H:\...\AutoIt3\SciTE     H:\...\AutoIt3      H:\...\AutoIt3\Include     (H:\ = Network Drive)

   88x31.png  Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind.

Share this post


Link to post
Share on other sites
Simpel

Hi,

thanks. I'm using a domain account. So that's the the point.

Any other possibility to check, when the user i use currently started working?

I have a mounting script. If this script is in startup it mostly fails because it had to delay a bit. So I want to check if it's to early because of running logon and wait 2 minutes or if app is started hours later and can try to mount instantly.

Regards, Conrad


SciTE4AutoIt = 3.7.3.0   AutoIt = 3.3.14.2   AutoItX64 = 0   OS = Win7Pro SP1   OSArch = X64   Language = 0407/german
H:\...\AutoIt3\SciTE     H:\...\AutoIt3      H:\...\AutoIt3\Include     (H:\ = Network Drive)

   88x31.png  Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind.

Share this post


Link to post
Share on other sites
BrewManNH

If you're using AD, check the AD UDF functions.


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites
Simpel

@BrewManNH: I will check.

I tested code from post 1 at another computer. It returns actual time but 7 days ago. The computer is running only some hours.

I did use this computer nearly every day with the same user with autologin.

Ideas?


SciTE4AutoIt = 3.7.3.0   AutoIt = 3.3.14.2   AutoItX64 = 0   OS = Win7Pro SP1   OSArch = X64   Language = 0407/german
H:\...\AutoIt3\SciTE     H:\...\AutoIt3      H:\...\AutoIt3\Include     (H:\ = Network Drive)

   88x31.png  Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind.

Share this post


Link to post
Share on other sites
jguinch

Can you try this one (with a local account only) ?

#include <Date.au3>

ConsoleWrite(_GetLogonTime() & @LF)
Func _GetLogonTime($sUserName = @UserName, $sComputerName = @ComputerName) ; Idea by trancexx: http://www.autoitscript.com/forum/topic/113611-if-isadmin-not-detected-as-admin/
    Local $aRet = DllCall("netapi32.dll", "long", "NetUserGetInfo", "wstr", $sComputerName, "wstr", $sUserName, "dword", 11, "ptr*", 0)
    If @error Or $aRet[0] Then Return SetError(1, 0, False)
    Local $sSeconds = DllStructGetData(DllStructCreate("ptr;ptr;ptr;ptr;dword;dword;dword;ptr;ptr;dword;dword;dword;dword;ptr;dword;ptr;dword;dword;byte;dword", $aRet[4]), 10)
    DllCall("netapi32.dll", "long", "NetApiBufferFree", "ptr", $aRet[4])
    Local $slastLogon = _DateAdd('s', Number($sSeconds), "1970/01/01 00:00:00")
    Return $slastLogon
EndFunc   ;==>_GetLogonTime

 

Share this post


Link to post
Share on other sites
Simpel

Much more better. I logged off and in at 20:34 local time and your result says 19:34.

Actual time zone is UTC+1. Is that possibly the reason for that 1 hour shift?


SciTE4AutoIt = 3.7.3.0   AutoIt = 3.3.14.2   AutoItX64 = 0   OS = Win7Pro SP1   OSArch = X64   Language = 0407/german
H:\...\AutoIt3\SciTE     H:\...\AutoIt3      H:\...\AutoIt3\Include     (H:\ = Network Drive)

   88x31.png  Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind.

Share this post


Link to post
Share on other sites
jguinch

Yes, This value is stored as the number of seconds that have elapsed since 00:00:00, January 1, 1970, GMT  (https://msdn.microsoft.com/fr-fr/library/windows/desktop/aa371106(v=vs.85).aspx)

 

Share this post


Link to post
Share on other sites
Subz

Recommend using AD UDF _AD_GetLastLoginDate function, as this checks all DCs for the LastLogontimestamp.

"The Lastlogon attribute is only updated on the domain controller that performs the authentication and is not replicated.  The LastLogontimestamp is replicated, but by default only if it is 14 days or more older than the previous value. "

Share this post


Link to post
Share on other sites
jguinch

You can also use WMI for emunerate all current sessions on the computer and get each logon time :

#RequireAdmin

Local $aUserInfos, $aLogonId, $iStartTime, $oSessions
Local $oWMI = ObjGet("winmgmts:/root/cimv2")
If Not IsObj($oWMI) Then Exit MsgBox(16, "Error", "WMI Error. Exit")

Local $oUserSessions = $oWMI.ExecQuery("select * from WIN32_LoggedOnUser")
For $oUserSession In $oUserSessions
    $aUserInfos = StringRegExp($oUserSession.Antecedent, '"([^"]+)"', 3)
    $aLogonId = StringRegExp($oUserSession.Dependent, '"([^"]+)"', 1)

    $oSessions = $oWMI.ExecQuery("select * from WIN32_LogonSession Where LogonId = " & $aLogonId[0])
    For $oSession In $oSessions
        $iStartTime = StringRegExpReplace($oSession.StartTime, "^(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2}).+", "$1/$2/$3 $4:$5:$6")
        ConsoleWrite($aUserInfos[0] & "\" & $aUserInfos[1] & @TAB & $iStartTime & @CRLF)
    Next
Next

 

Share this post


Link to post
Share on other sites
Simpel

Thanks,

it works great for me. We do have only single-user-mode.

Regards, Conrad


SciTE4AutoIt = 3.7.3.0   AutoIt = 3.3.14.2   AutoItX64 = 0   OS = Win7Pro SP1   OSArch = X64   Language = 0407/german
H:\...\AutoIt3\SciTE     H:\...\AutoIt3      H:\...\AutoIt3\Include     (H:\ = Network Drive)

   88x31.png  Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind.

Share this post


Link to post
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

  • Similar Content

    • nooneclose
      By nooneclose
      I need help turning this string "20180913221626" into a formatted time string.
      I need to go from this: 20180913221626
      to this: 09/13/2018 10:16 PM
      I do not always know what the date will be so I can not just use a variable I need to actually convert/format. 
      I did see an older post in the forms that was basically the same question only the other guy did not post the working code and I can not figure out how to use _AD_GetObjectProperties properly to get what I want. 
      As always any help would be appreciated. 
      Here is the code I use to find the date, but it always gives me the unformatted version. 
      ;retrieve the items object $oItem = $oOutlook.Session.GetItemFromID($aItems[1][0], Default) $oItem.GetInspector $eSentOn = $oItem.SentOn ; When was the email sent? MsgBox("", "Sent On of the email", $eSentOn) ;******************************************************************************* ; Formats the date and time from the email ;******************************************************************************* ;Local $fDatenTime = _DateTimeFormat($eSentOn, 1) ;MsgBox("", "Formatted email time", $fDatenTime) $aProperties = _AD_GetObjectProperties($eSentOn) _ArrayDisplay($aProperties, "Did the conversion work?")  
    • Jemboy
      By Jemboy
      Hi,
      Ones(some times twice) a month I get an e-mail with zip file, which has price updates from a supplier.
      I have to upload the file to an FTP to get it processed.
      When uploading the file, it will get "timestamped" with the time and date at which time the file was uploaded.
      Normally this is fine, because I mostly upload the file the same day.
      Sometimes it may take 1 or 2 days before I can upload the file.
      For historical purpose, I would like to have the file timestamped with the original date.
      I have tried using:  _FTP_Command ( $hFTPSession, "MFCT YYYYMMDDHHMMSS path") 
      however this command does not work or change the timestamp as I expected.
      Does anyone now a way how I can change the timestamp of a FTP-file?
    • Rskm
      By Rskm
      Hi, for a script of mine, I wish to keep a time frame on till how the program will work.. basically, I want the program to read the date and if the read date < 'a particular date', the program continues, else it exit. I don't want to read the time from the computer as the program can be fooled by resetting the pc time. is there a way to read time from internet - so that the user cannot fool the program by date reset? thanks
    • Shedunn
      By Shedunn
      I've been looking through some different functions(not sure if that's the right word) to get the Date and time and I can't find one that doesn't include "/ " or ":" in what is returned.

      I'm trying to create a file name with this format "QuickConfig_MMDDYYYY_HHMM"  (doesn't matter if 24 or 12hr format)
      #include <Date.au3> Func _SaveConfig MouseClick('primary',155, 46, 1, 0) ;clicks save as WinWait('Save bluePRINT Configuration As...','', 4) MouseClick('primary',632, 47, 1, 0) ;clicks the file path bar $Documents = @MyDocumentsDir $FilePath = $Documents & '\BP3 Configs' Send($FilePath) Send('{ENTER}') MouseClick('primary',166, 580, 1, 0) ;clicks file name bar $FileName = 'QuickConfig_' & _NowDate & '_' & _NowTime Send($FileName) Send('{ENTER}') EndFunc  
       
      I'm wondering if there is a function somewhere to do this?
×