Simpel Posted January 26, 2017 Posted January 26, 2017 (edited) 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 Edited April 25, 2019 by Simpel [Solved] SciTE4AutoIt = 3.7.3.0 AutoIt = 3.3.14.2 AutoItX64 = 0 OS = Win_10 Build = 19044 OSArch = X64 Language = 0407/german H:\...\AutoIt3\SciTE H:\...\AutoIt3 H:\...\AutoIt3\Include (H:\ = Network Drive) Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind.
jguinch Posted January 26, 2017 Posted January 26, 2017 2221 = NERR_UserNotFound Are you using a domain account ? See the remarks section from MSDN : https://msdn.microsoft.com/fr-fr/library/windows/desktop/aa370654(v=vs.85).aspx Spoiler Network configuration UDF, _DirGetSizeByExtension, _UninstallList Firefox ConfigurationArray multi-dimensions, Printer Management UDF
Simpel Posted January 26, 2017 Author Posted January 26, 2017 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 = Win_10 Build = 19044 OSArch = X64 Language = 0407/german H:\...\AutoIt3\SciTE H:\...\AutoIt3 H:\...\AutoIt3\Include (H:\ = Network Drive) Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind.
BrewManNH Posted January 26, 2017 Posted January 26, 2017 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 GudeHow 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
Simpel Posted January 26, 2017 Author Posted January 26, 2017 @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 = Win_10 Build = 19044 OSArch = X64 Language = 0407/german H:\...\AutoIt3\SciTE H:\...\AutoIt3 H:\...\AutoIt3\Include (H:\ = Network Drive) Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind.
jguinch Posted January 26, 2017 Posted January 26, 2017 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 Spoiler Network configuration UDF, _DirGetSizeByExtension, _UninstallList Firefox ConfigurationArray multi-dimensions, Printer Management UDF
Simpel Posted January 26, 2017 Author Posted January 26, 2017 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 = Win_10 Build = 19044 OSArch = X64 Language = 0407/german H:\...\AutoIt3\SciTE H:\...\AutoIt3 H:\...\AutoIt3\Include (H:\ = Network Drive) Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind.
jguinch Posted January 26, 2017 Posted January 26, 2017 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) Spoiler Network configuration UDF, _DirGetSizeByExtension, _UninstallList Firefox ConfigurationArray multi-dimensions, Printer Management UDF
Subz Posted January 27, 2017 Posted January 27, 2017 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. "
jguinch Posted January 28, 2017 Posted January 28, 2017 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 Spoiler Network configuration UDF, _DirGetSizeByExtension, _UninstallList Firefox ConfigurationArray multi-dimensions, Printer Management UDF
Simpel Posted January 28, 2017 Author Posted January 28, 2017 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 = Win_10 Build = 19044 OSArch = X64 Language = 0407/german H:\...\AutoIt3\SciTE H:\...\AutoIt3 H:\...\AutoIt3\Include (H:\ = Network Drive) Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind.
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