Sign in to follow this  
Followers 0
WhOOt

How long has your pc been turned on?

6 posts in this topic

Hey again guys :)

I was making this program, so that I could how long time I spent at my computer.. It's not something big, just a little thing to keep up my programming :D

I was thinking if someone could correct some of my bads? And also my very unorganized programming is bad for the script.. :D

Thanks for anyone, who is willing to help :D

And to everyone, who took his time to read the topic :P

Thanks

WhOOt

::BTW, I did not write all of this, I borrowed some of the code from others from the site :P

Autoit_Example_scripts.rar

Share this post


Link to post
Share on other sites



Ha, I didn't think anyone would actually use that function.


[center]Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.[/center]

Share this post


Link to post
Share on other sites

@command prompt-

systeminfo | find "System Up Time:"

Share this post


Link to post
Share on other sites

@command prompt-

systeminfo | find "System Up Time:"

Mines much faster :)
#include <array.au3>
$nTimer1 = TimerInit()
$aArray1 = _TimeSystemRestart()
$nDiff1 = TimerDiff($nTimer1)

$nTimer2 = TimerInit()
$aArray2 = _TimeSystemRestartCMD()
$nDiff2 = TimerDiff($nTimer2)

ConsoleWrite(@LF & 'Timer 1: ' & $nDiff1 & @LF & @LF & 'Timer 1: ' & $nDiff2 & @LF)
_ArrayDisplay($aArray1, 'DLL')
_ArrayDisplay($aArray2, 'CMD')

Func _TimeSystemRestart()
    Local $iSubTotal = DllCall('kernel32.dll', 'int', 'GetTickCount')
    If Not IsArray($iSubTotal) Then Return SetError(1, 0, 0)
    $iSubTotal = $iSubTotal[0] / 1000
    Local $iWeek = Int(($iSubTotal / 604800))
    If $iWeek > 0 Then $iSubTotal -= $iWeek * 604800
    Local $iDay = Int(($iSubTotal / 86400))
    If $iDay > 0 Then $iSubTotal -= $iDay * 86400
    Local $iHour = Int(($iSubTotal / 3600))
    Local $iMin = Int(($iSubTotal - ($iHour * 3600)) / 60)
    Local $iSec = Int(($iSubTotal - $iHour * 3600) - ($iMin * 60))
    Return StringSplit(StringFormat('%02d', $iWeek) & ':' & $iDay & ':' & StringFormat('%02d', $iHour) & ':' & _
        StringFormat('%02d', $iMin) & ':' & StringFormat('%02d', $iSec), ':')
EndFunc

Func _TimeSystemRestartCMD()
    Local $iPID = Run(@ComSpec & ' /c systeminfo | find "System Up Time:"', '', @SW_HIDE, 6)
    Local $sHold = ''
    While Not @error
        $sHold &= StdoutRead($iPID)
    WEnd
    If $sHold = '' Then Return SetError(1, 0, '')
    $sHold = StringStripWS($sHold, 8)
    $sHold = StringReplace($sHold, 'SystemUpTime:', '')
    If Not StringInStr($sHold, 'Minutes') Then $sHold = '0Minutes,' & $sHold
    If Not StringInStr($sHold, 'Hours') Then $sHold = '0Hours,' & $sHold
    If Not StringInStr($sHold, 'Days') Then $sHold = '0Days,' & $sHold
    If Not StringInStr($sHold, 'Weeks') Then $sHold = '0Weeks,' & $sHold
    Local $aArray = StringRegExp($sHold, '(\d+).*?(\d+).*?(\d+).*?(\d+).*?(\d+)', 1)
    If IsArray($aArray) = 0 Then Return SetError(2, 0, '')
    Local $aReturn[UBound($aArray) + 1], $iAdd = 0
    For $iCC = 0 To UBound($aArray) - 1
        $iAdd += 1
        If $iCC <> 1 Then $aReturn[$iAdd] &= StringFormat('%02d', $aArray[$iCC])
        If $iCC = 1 Then $aReturn[$iAdd] &= $aArray[$iCC]
    Next
    Return $aReturn
EndFunc

[center]Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.[/center]

Share this post


Link to post
Share on other sites

Mines much faster

lol... :)


- Dan [Website]

Share this post


Link to post
Share on other sites

Mines much faster :D

#include <array.au3>
$nTimer1 = TimerInit()
$aArray1 = _TimeSystemRestart()
$nDiff1 = TimerDiff($nTimer1)

$nTimer2 = TimerInit()
$aArray2 = _TimeSystemRestartCMD()
$nDiff2 = TimerDiff($nTimer2)

ConsoleWrite(@LF & 'Timer 1: ' & $nDiff1 & @LF & @LF & 'Timer 1: ' & $nDiff2 & @LF)
_ArrayDisplay($aArray1, 'DLL')
_ArrayDisplay($aArray2, 'CMD')

Func _TimeSystemRestart()
    Local $iSubTotal = DllCall('kernel32.dll', 'int', 'GetTickCount')
    If Not IsArray($iSubTotal) Then Return SetError(1, 0, 0)
    $iSubTotal = $iSubTotal[0] / 1000
    Local $iWeek = Int(($iSubTotal / 604800))
    If $iWeek > 0 Then $iSubTotal -= $iWeek * 604800
    Local $iDay = Int(($iSubTotal / 86400))
    If $iDay > 0 Then $iSubTotal -= $iDay * 86400
    Local $iHour = Int(($iSubTotal / 3600))
    Local $iMin = Int(($iSubTotal - ($iHour * 3600)) / 60)
    Local $iSec = Int(($iSubTotal - $iHour * 3600) - ($iMin * 60))
    Return StringSplit(StringFormat('%02d', $iWeek) & ':' & $iDay & ':' & StringFormat('%02d', $iHour) & ':' & _
        StringFormat('%02d', $iMin) & ':' & StringFormat('%02d', $iSec), ':')
EndFunc

Func _TimeSystemRestartCMD()
    Local $iPID = Run(@ComSpec & ' /c systeminfo | find "System Up Time:"', '', @SW_HIDE, 6)
    Local $sHold = ''
    While Not @error
        $sHold &= StdoutRead($iPID)
    WEnd
    If $sHold = '' Then Return SetError(1, 0, '')
    $sHold = StringStripWS($sHold, 8)
    $sHold = StringReplace($sHold, 'SystemUpTime:', '')
    If Not StringInStr($sHold, 'Minutes') Then $sHold = '0Minutes,' & $sHold
    If Not StringInStr($sHold, 'Hours') Then $sHold = '0Hours,' & $sHold
    If Not StringInStr($sHold, 'Days') Then $sHold = '0Days,' & $sHold
    If Not StringInStr($sHold, 'Weeks') Then $sHold = '0Weeks,' & $sHold
    Local $aArray = StringRegExp($sHold, '(\d+).*?(\d+).*?(\d+).*?(\d+).*?(\d+)', 1)
    If IsArray($aArray) = 0 Then Return SetError(2, 0, '')
    Local $aReturn[UBound($aArray) + 1], $iAdd = 0
    For $iCC = 0 To UBound($aArray) - 1
        $iAdd += 1
        If $iCC <> 1 Then $aReturn[$iAdd] &= StringFormat('%02d', $aArray[$iCC])
        If $iCC = 1 Then $aReturn[$iAdd] &= $aArray[$iCC]
    Next
    Return $aReturn
EndFunc
Yea, but what I am looking for, is one that saves your current 'on-time', and adds it to a file or something, and adds then up, so that you can see current on time and All on-'times added up.

So that I can see if I've been on my computer for 1 week, in a month :)

Thanks

WhOOt

Share this post


Link to post
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
Sign in to follow this  
Followers 0