FinalVersion Posted February 18, 2010 Share Posted February 18, 2010 Simple script that keeps track of your computers uptime, also it doesn't use timers. System Uptime.zip [center][+] Steam GUI [+][+] Clipboard Tool [+][+] System :: Uptime [+][+] StarCraft II Mouse Trap [+][/center] Link to comment Share on other sites More sharing options...
spudw2k Posted February 18, 2010 Share Posted February 18, 2010 (edited) Neat. I made a CMDLine version. It uses WMI so it can support Remote use. edit: Revisted code and simplified WMI call 2017-10-23 Added Ping test before WMI connection attempt and fail condition Spoiler expandcollapse popup#Region - Includes and Initilization #AutoIt3Wrapper_Change2CUI=Y #include <Date.au3> #EndRegion #Region - Command Line Parameter Execution/Logic If @Compiled Then If $cmdline[0] Then ;Check for CMD Lime Parameters If StringInstr($cmdlineraw,"?") Then ;Help ConsoleWrite(@CRLF & "Description:" & @CRLF & @TAB & "Displays system up time for local or remote machines." & @CRLF) ConsoleWrite(@CRLF & "Parameter List:" & @CRLF & @TAB & "/?" & @TAB & @TAB & @TAB & "Displays this help/usage." & @CRLF) ConsoleWrite(@CRLF & "Examples:" & @CRLF & @TAB & @ScriptName & @CRLF) ConsoleWrite(@TAB & @ScriptName & " hostname1 hostname2 hostname3" & @CRLF) Exit EndIf For $iX = 1 To $cmdline[0] ; ConsoleWrite(StringUpper($cmdline[$iX]) & " " & _Uptime($cmdline[$iX])&@CRLF) Next Else ConsoleWrite(_Uptime() & @CRLF) EndIf Else MsgBox(0,"Uptime:",_Uptime()) EndIf #EndRegion #Region - Uptime Function (Main) Func _Uptime($sComputer = @ComputerName) $iPing = Ping($sComputer,4000) If Not $iPing Then Return "Failed to Reach" $oWMIService = ObjGet("winmgmts:\\" & $sComputer & "\root\cimv2") If Not IsObj($oWMIService) Then Return "Failed to Connect" $oColOperatingSystems = $oWMIService.ExecQuery("Select LastBootUpTime from Win32_OperatingSystem") For $oOS in $oColOperatingSystems Local $sBootup = $oOS.LastBootUpTime Local $sLastBootupTime = __WMIDateStringToDate($sBootup) Next $oColOperatingSystems = 0 $oWMIService = 0 Local $sUpTime = __FormatUptime($sLastBootupTime) Return "Last Boot: " & $sLastBootupTime & @CRLF & "Uptime: " & $sUpTime EndFunc #EndRegion #Region - Internal Functions Func __FormatUptime($sLastBootupTime) Local $aDateDiffs=[[0,24," day"],[0,60," hour"],[0,60," minute"],[0,1," second"]] Local $aDateDiff = StringSplit("D|h|n|s","|") Local $sNow = _NowCalc() For $sDiff = 1 to $aDateDiff[0] $aDateDiffs[$sDiff-1][0] = _DateDiff($aDateDiff[$sDiff], $sLastBootUpTime, $sNow) Next Local $iUbound = UBound($aDateDiffs)-1 For $iX = $iUbound To 0 Step -1 If $iX > 0 Then If $aDateDiffs[$iX-1][0] > 0 Then $aDateDiffs[$iX][0] = ($aDateDiffs[$iX][0]-($aDateDiffs[$iX-1][0]*$aDateDiffs[$iX-1][1])) EndIf Next Local $sUptime = "" For $iX = 0 To $iUbound If $aDateDiffs[$iX][0] > 0 Then $sUptime &= $aDateDiffs[$iX][0] & $aDateDiffs[$iX][2] If $aDateDiffs[$iX][0] > 1 Then $sUptime &= "s" If $iX < $iUbound Then $sUptime &= ", " EndIf Next Return $sUptime EndFunc Func __WMIDateStringToDate($sBootup) Return StringLeft($sBootup,4) & "/" & StringMid($sBootup, 5, 2) & "/" & StringMid($sBootup, 7, 2) & " " & StringMid($sBootup, 9, 2) & ":" & StringMid($sBootup, 11, 2) & ":" & StringMid($sBootup, 13, 2) EndFunc #EndRegion Edited October 23, 2017 by spudw2k source code update / cleanup Spoiler Things I've Made: Always On Top Tool ◊ AU History ◊ Deck of Cards ◊ HideIt ◊ ICU ◊ Icon Freezer ◊ Ipod Ejector ◊ Junos Configuration Explorer ◊ Link Downloader ◊ MD5 Folder Enumerator ◊ PassGen ◊ Ping Tool ◊ Quick NIC ◊ Read OCR ◊ RemoteIT ◊ SchTasksGui ◊ SpyCam ◊ System Scan Report Tool ◊ System UpTime ◊ Transparency Machine ◊ VMWare ESX Builder Misc Code Snippets: ADODB Example ◊ CheckHover ◊ Detect SafeMode ◊ DynEnumArray ◊ GetNetStatData ◊ HashArray ◊ IsBetweenDates ◊ Local Admins ◊ Make Choice ◊ Recursive File List ◊ Remove Sizebox Style ◊ Retrieve PNPDeviceID ◊ Retrieve SysListView32 Contents ◊ Set IE Homepage ◊ Tickle Expired Password ◊ Transpose Array Projects: Drive Space Usage GUI ◊ LEDkIT ◊ Plasma_kIt ◊ Scan Engine Builder ◊ SpeeDBurner ◊ SubnetCalc Cool Stuff: AutoItObject UDF ◊ Extract Icon From Proc ◊ GuiCtrlFontRotate ◊ Hex Edit Funcs ◊ Run binary ◊ Service_UDF Link to comment Share on other sites More sharing options...
FinalVersion Posted February 19, 2010 Author Share Posted February 19, 2010 Nice, but mines more colorful [center][+] Steam GUI [+][+] Clipboard Tool [+][+] System :: Uptime [+][+] StarCraft II Mouse Trap [+][/center] Link to comment Share on other sites More sharing options...
Ruud0209 Posted July 9, 2010 Share Posted July 9, 2010 Nice, but mines more colorful Plus it calculation is "Last Boot". The other script I tried but gives another value if the system has been in standby. Last boot was 18 hours ago and last coming out of standby was 3.5 ours ago.Different values, different needs, but I like the kernel way over the WMI way.Thanks to the both of you anyway... Link to comment Share on other sites More sharing options...
spudw2k Posted July 9, 2010 Share Posted July 9, 2010 Plus it calculation is "Last Boot". The other script I tried but gives another value if the system has been in standby. Last boot was 18 hours ago and last coming out of standby was 3.5 ours ago.Interesting observation, but I couldn't replicate the problem by putting my machine in standby.I went with WMI for remote PCs; and for some reason the WMI call reflects the same time that "systeminfo" produces. Final's version is almost 1 minute behind, but that's not a big deal. Spoiler Things I've Made: Always On Top Tool ◊ AU History ◊ Deck of Cards ◊ HideIt ◊ ICU ◊ Icon Freezer ◊ Ipod Ejector ◊ Junos Configuration Explorer ◊ Link Downloader ◊ MD5 Folder Enumerator ◊ PassGen ◊ Ping Tool ◊ Quick NIC ◊ Read OCR ◊ RemoteIT ◊ SchTasksGui ◊ SpyCam ◊ System Scan Report Tool ◊ System UpTime ◊ Transparency Machine ◊ VMWare ESX Builder Misc Code Snippets: ADODB Example ◊ CheckHover ◊ Detect SafeMode ◊ DynEnumArray ◊ GetNetStatData ◊ HashArray ◊ IsBetweenDates ◊ Local Admins ◊ Make Choice ◊ Recursive File List ◊ Remove Sizebox Style ◊ Retrieve PNPDeviceID ◊ Retrieve SysListView32 Contents ◊ Set IE Homepage ◊ Tickle Expired Password ◊ Transpose Array Projects: Drive Space Usage GUI ◊ LEDkIT ◊ Plasma_kIt ◊ Scan Engine Builder ◊ SpeeDBurner ◊ SubnetCalc Cool Stuff: AutoItObject UDF ◊ Extract Icon From Proc ◊ GuiCtrlFontRotate ◊ Hex Edit Funcs ◊ Run binary ◊ Service_UDF Link to comment Share on other sites More sharing options...
FinalVersion Posted July 21, 2010 Author Share Posted July 21, 2010 Interesting observation, but I couldn't replicate the problem by putting my machine in standby.I went with WMI for remote PCs; and for some reason the WMI call reflects the same time that "systeminfo" produces. Final's version is almost 1 minute behind, but that's not a big deal.Blame that on Microsoft [center][+] Steam GUI [+][+] Clipboard Tool [+][+] System :: Uptime [+][+] StarCraft II Mouse Trap [+][/center] Link to comment Share on other sites More sharing options...
Yanze Posted February 4, 2011 Share Posted February 4, 2011 Simple script that keeps track of your computers uptime, also it doesn't use timers. System Uptime.zip This script seems very usefull, is it possible to place the uptime in a variable that I can use to write a reg key? Link to comment Share on other sites More sharing options...
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