Jump to content

How to get the computer uptime with Autoit...


ainner
 Share

Recommended Posts

I want to perform an action if a computer has been up for more than 3 days. Right now the only way I found of doing it is by using a VbScript...

Since I don't wanna overcomplicated things I would be happy if someone would have a solution not requiring VbScript or at least least using it as simple as possible...

Thx

Edited by ainner
Link to comment
Share on other sites

I want to perform an action if a computer has been up for more than 3 days. Right now the only way I found of doing it is by using a VbScript...

Since I don't wanna overcomplicated things I would be happy if someone would have a solution not requiring VbScript or at least least using it as simple as possible...

Thx

There is timerinit() functions and time and date functions see the help file, you could get the current date and time and work out which date and time you need to do what from that, periodically check the current date and time and if it matches then perform your action, or timerinit() but I don't know if using the timerinit() is acceptable over a 3 day period or not.

Link to comment
Share on other sites

needs beta

#include <Date.au3>

$wbemFlagReturnImmediately = 0x10
$wbemFlagForwardOnly = 0x20
$colItems = ""
$strComputer = "localhost"

$Output = ""
$Output = $Output & "Computer: " & $strComputer & @CRLF
$Output = $Output & "==========================================" & @CRLF
$objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\root\CIMV2")
$colItems = $objWMIService.ExecQuery ("SELECT * FROM Win32_OperatingSystem", "WQL", _
      $wbemFlagReturnImmediately + $wbemFlagForwardOnly)

If IsObj($colItems) Then
   For $objItem In $colItems
      $LastBootUp = WMIDateStringToDate($objItem.LastBootUpTime)
      $LocalDateTime = WMIDateStringToDate($objItem.LocalDateTime)
      
      $Output = $Output & "In Years: " & _DateDiff("Y", $LastBootUp, $LocalDateTime) & @CRLF
      $Output = $Output & "In Months: " & _DateDiff("M", $LastBootUp, $LocalDateTime) & @CRLF
      $Output = $Output & "In Weeks: " & _DateDiff("W", $LastBootUp, $LocalDateTime) & @CRLF
      $Output = $Output & "In Days: " & _DateDiff("D", $LastBootUp, $LocalDateTime) & @CRLF
      $Output = $Output & "In Hours: " & _DateDiff("h", $LastBootUp, $LocalDateTime) & @CRLF
      $Output = $Output & "In Minutes: " & _DateDiff("n", $LastBootUp, $LocalDateTime) & @CRLF
      $Output = $Output & "In Seconds: " & _DateDiff("s", $LastBootUp, $LocalDateTime) & @CRLF
      $Output = $Output & "LastBootUpTime: " & $LastBootUp & @CRLF
      $Output = $Output & "LocalDateTime: " & $LocalDateTime & @CRLF
      If MsgBox(1, "WMI Output", $Output) = 2 Then ExitLoop
      $Output = ""
   Next
Else
   MsgBox(0, "WMI Output", "No WMI Objects Found for class: " & "Win32_OperatingSystem")
EndIf


Func WMIDateStringToDate($dtmDate)
   
   Return (StringMid($dtmDate, 1, 4) & "/" & _
         StringMid($dtmDate, 5, 2) & "/" & _
         StringMid($dtmDate, 7, 2) & _
         " " & StringMid($dtmDate, 9, 2) & ":" & StringMid($dtmDate, 11, 2) & ":" & StringMid($dtmDate, 13, 2))
EndFunc  ;==>WMIDateStringToDate

SciTE for AutoItDirections for Submitting Standard UDFs

 

Don't argue with an idiot; people watching may not be able to tell the difference.

 

Link to comment
Share on other sites

Thx a lot it's working like a charm...

gafrost : The code you provided is vbscript right ? You are able to run thsi under autoit with the beta ???

Nope, it is AutoIt, just use WMI thru Objects

Look for Scriptomatic in the Scripts and Scraps portion of the forum, you'll find that a handy tool.

Gary

SciTE for AutoItDirections for Submitting Standard UDFs

 

Don't argue with an idiot; people watching may not be able to tell the difference.

 

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