Jump to content

Recommended Posts

Posted

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 B)

Thanks in advance,

Kate

Posted (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 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.

 

Posted

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)

NEWHeader1.png

Posted (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 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.

 

Posted

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]

Posted

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.

 

Posted (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 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.

 

Posted

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

  • 4 years later...
Posted

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
Posted

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

Posted

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
  • 13 years later...
Posted

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

Posted (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 by Nine

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
  • Recently Browsing   0 members

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