Kate Posted November 21, 2005 Posted November 21, 2005 Hello, Is there a way to use AutoIT to obtain the boot time of the computer? I'm looking to create a nag screen for users who don't reboot Thanks in advance, Kate
GaryFrost Posted November 21, 2005 Posted November 21, 2005 (edited) requires beta, but i think this is what your looking for (can be done remotely, just replace @ComputerName with the name of the computer) $wbemFlagReturnImmediately = 0x10 $wbemFlagForwardOnly = 0x20 $colItems = "" $strComputer = @ComputerName $Output="" $Output = $Output & "Computer: " & $strComputer & @CRLF $Output = $Output & "==========================================" & @CRLF $objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\root\CIMV2") $colItems = $objWMIService.ExecQuery("SELECT * FROM Win32_PerfFormattedData_PerfOS_System", "WQL", _ $wbemFlagReturnImmediately + $wbemFlagForwardOnly) If IsObj($colItems) then For $objItem In $colItems $uptime = $objItem.SystemUpTime If $uptime > 60 Then $uptime = $uptime / 60; convert the seconds to minutes If $uptime > 60 Then $uptime = $uptime / 60; convert the minutes to hours If $uptime > 24 Then; convert hours to days $uptime = Number(StringFormat("%.2f",$uptime / 24)) If $uptime > 1.0 Then; uptime more than 1 day $Output = $Output & "SystemUpTime: " & $uptime & @CRLF if Msgbox(1,"WMI Output",$Output) = 2 then ExitLoop EndIf EndIf EndIf EndIf $Output="" Next Else Msgbox(0,"WMI Output","No WMI Objects Found for class: " & "Win32_PerfFormattedData_PerfOS_System" ) Endif Edited November 22, 2005 by gafrost SciTE for AutoItDirections for Submitting Standard UDFs Don't argue with an idiot; people watching may not be able to tell the difference.
Valuater Posted November 21, 2005 Posted November 21, 2005 Sometimes i think to myself... wow, this is what gafrost used to do..cool maybe i am catching up to his skills... then i see a post like this that shows me how much more gafrost has learned and i feel dumb .... all over again nice script gary 8)
w0uter Posted November 22, 2005 Posted November 22, 2005 or alternatively you could use GetTickCount() from kernel32.dll My UDF's:;mem stuff_Mem;ftp stuff_FTP ( OLD );inet stuff_INetGetSource ( OLD )_INetGetImage _INetBrowse ( Collection )_EncodeUrl_NetStat_Google;random stuff_iPixelSearch_DiceRoll
GaryFrost Posted November 22, 2005 Posted November 22, 2005 (edited) $ret = DllCall("kernel32.dll","long","GetTickCount") If IsArray($ret) Then $uptime = $ret[0] / 1000; convert miliseconds to seconds If $uptime > 60 Then $uptime = $uptime / 60; convert the seconds to minutes If $uptime > 60 Then $uptime = $uptime / 60; convert the minutes to hours If $uptime > 24 Then; convert hours to days $uptime = Number(StringFormat("%.2f",$uptime / 24)) If $uptime > 1.0 Then; uptime more than 1 day MsgBox(0,"Uptime", $uptime) EndIf EndIf EndIf EndIf EndIf Edited November 22, 2005 by gafrost SciTE for AutoItDirections for Submitting Standard UDFs Don't argue with an idiot; people watching may not be able to tell the difference.
herewasplato Posted November 22, 2005 Posted November 22, 2005 I had to move the msgbox to get an output since uptime was not more than 24 hours. $ret = DllCall("kernel32.dll","long","GetTickCount") ; convert miliseconds to seconds If IsArray($ret) Then $uptime = $ret[0] / 1000 ; convert the seconds to minutes If $uptime > 60 Then $uptime = $uptime / 60 ; convert the minutes to hours If $uptime > 60 Then $uptime = $uptime / 60 ; convert hours to days If $uptime > 24 Then $uptime = Number(StringFormat("%.2f",$uptime / 24)) MsgBox(0,"Uptime", $uptime)What formatting did you have in mind if greater than one day? ...and thanks for the code... [size="1"][font="Arial"].[u].[/u][/font][/size]
GaryFrost Posted November 22, 2005 Posted November 22, 2005 I had to move the msgbox to get an output since uptime was not more than 24 hours. $ret = DllCall("kernel32.dll","long","GetTickCount") ; convert miliseconds to seconds If IsArray($ret) Then $uptime = $ret[0] / 1000 ; convert the seconds to minutes If $uptime > 60 Then $uptime = $uptime / 60 ; convert the minutes to hours If $uptime > 60 Then $uptime = $uptime / 60 ; convert hours to days If $uptime > 24 Then $uptime = Number(StringFormat("%.2f",$uptime / 24)) MsgBox(0,"Uptime", $uptime)What formatting did you have in mind if greater than one day? ...and thanks for the code... Leave your system on for more than a day and see what it returns, on my system right now it returned 3.93 SciTE for AutoItDirections for Submitting Standard UDFs Don't argue with an idiot; people watching may not be able to tell the difference.
GaryFrost Posted November 22, 2005 Posted November 22, 2005 (edited) $ret = DllCall("kernel32.dll", "long", "GetTickCount") If IsArray($ret) Then $type = "Seconds" $uptime = Number(StringFormat("%.2f", $ret[0] / 1000)); convert miliseconds to seconds If $uptime > 60 Then $type = "Minute(s)" $uptime = Number(StringFormat("%.2f", $uptime / 60)); convert the seconds to minutes If $uptime > 60 Then $type = "Hour(s)" $uptime = Number(StringFormat("%.2f", $uptime / 60)); convert the minutes to hours If $uptime > 24 Then; convert hours to days $type = "Day(s)" $uptime = Number(StringFormat("%.2f", $uptime / 24)) EndIf EndIf EndIf EndIf MsgBox(0, "Uptime", $uptime & " " & $type) Edited November 22, 2005 by gafrost SciTE for AutoItDirections for Submitting Standard UDFs Don't argue with an idiot; people watching may not be able to tell the difference.
jpm Posted November 22, 2005 Posted November 22, 2005 incase you like another formating$ret = DllCall("kernel32.dll", "long", "GetTickCount") If IsArray($ret) Then $msec=StringRight("00" & mod($ret[0],1000),3) $uptime=floor($ret[0]/1000) $sec=StringRight("00" & mod($uptime,60),2) If $uptime >= 60 Then $uptime= floor($uptime/60) $min=StringRight("00" & mod($uptime,60),2) If $uptime >= 60 Then $uptime=floor($uptime/60) $hour = StringRight("00" & mod($uptime,24),2) If $uptime >= 24 Then; convert hours to days $day=floor($uptime/24) $type="" if $day >1 then $type = "s" $type = " Day" & $type & " " EndIf EndIf EndIf MsgBox(0, "Uptime", $day & $type & $hour & ":" & $min &":"& $sec & '.'& $msec) EndIf
ranhalt Posted January 14, 2010 Posted January 14, 2010 Just a shorter way to do the same thing. $ret = DllCall("kernel32.dll","long","GetTickCount") If IsArray($ret) Then $uptime = Round(($ret[0] / 3600000),1); convert miliseconds to hours MsgBox(0,"Uptime", $uptime,3) EndIf
Naveed Posted January 15, 2010 Posted January 15, 2010 Just a shorter way to do the same thing. $ret = DllCall("kernel32.dll","long","GetTickCount") If IsArray($ret) Then $uptime = Round(($ret[0] / 3600000),1); convert miliseconds to hours MsgBox(0,"Uptime", $uptime,3) EndIf A little help needed.. How would you use the dllcall function to check uptime on a remote machine? Thanks
KaFu Posted January 15, 2010 Posted January 15, 2010 On remote machines? I think WMI is the best way to go...requires of course active WMI and sufficient access rights on remote machine. $wbemFlagReturnImmediately = 0x10 $wbemFlagForwardOnly = 0x20 $colItems = "" $strComputer = "localhost" $Output="" $Output &= "Computer: " & $strComputer & @CRLF $Output &= "==========================================" & @CRLF $objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\root\CIMV2") $colItems = $objWMIService.ExecQuery("SELECT * FROM Win32_PerfFormattedData_PerfOS_System", "WQL", _ $wbemFlagReturnImmediately + $wbemFlagForwardOnly) If IsObj($colItems) then For $objItem In $colItems $Output &= "SystemUpTime: " & $objItem.SystemUpTime ; in seconds if Msgbox(1,"WMI Output",$Output) = 2 then ExitLoop $Output="" Next Else Msgbox(0,"WMI Output","No WMI Objects Found for class: " & "Win32_PerfFormattedData_PerfOS_System" ) Endif OS: Win10-22H2 - 64bit - German, AutoIt Version: 3.3.16.1, AutoIt Editor: SciTE, Website: https://funk.eu AMT - Auto-Movie-Thumbnailer (2024-Oct-13) BIC - Batch-Image-Cropper (2023-Apr-01) COP - Color Picker (2009-May-21) DCS - Dynamic Cursor Selector (2024-Oct-13) HMW - Hide my Windows (2024-Oct-19) HRC - HotKey Resolution Changer (2012-May-16) ICU - Icon Configuration Utility (2018-Sep-16) SMF - Search my Files (2024-Oct-20) - THE file info and duplicates search tool SSD - Set Sound Device (2017-Sep-16)
mike1950r Posted April 21, 2023 Posted April 21, 2023 Hi all, sorry if i jump into this thread a bit late <bg> Just about formating into: MsgBox(0, "Uptime", $day & $type & $hour & ":" & $min &":"& $sec & '.'& $msec) If I use: _WinAPI_GetDurationFormat(0, $ret[0] * 1000 * 10) I get slightly different values (2 sec difference) Which format procedure should I trust? Cheers mike
Developers Jos Posted April 22, 2023 Developers Posted April 22, 2023 How are those variables filled? Show a short script that is runnable showing your issue.... SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past.
Nine Posted April 22, 2023 Posted April 22, 2023 (edited) With this code I obtain exactly the same strings : #include <WinAPISys.au3> #include <WinAPILocale.au3> Local $iTime = _WinAPI_GetTickCount() $sTime = _WinAPI_GetDurationFormat($LOCALE_USER_DEFAULT, $iTime * 10000, "hh:mm:ss") ConsoleWrite($sTime & @CRLF) $iTime = Int($iTime/1000) Local $iSec = Mod($iTime, 60) $iTime = Int($iTime / 60) Local $iMin = Mod($iTime, 60) Local $iHour = Int($iTime / 60) ConsoleWrite(StringFormat("%02i:%02i:%02i", $iHour, $iMin, $iSec) & @CRLF) Edited April 22, 2023 by Nine “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Debug Messages Monitor UDF Screen Scraping Round Corner GUI UDF Multi-Threading Made Easy Interface Object based on Tag
mike1950r Posted April 22, 2023 Posted April 22, 2023 Yes, sorry, I have to confirm also same results. I must have lost those 2 seconds anywhere in the script. Thanks anyway. Cheers mike
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