获取给定时间范围内Windows机器的活动时间



我想知道在给定的时间范围内我在系统上花费的总时间。例如:从上午9点到晚上9点,我应该确定我的机器处于锁定状态的时间,我的机器处于睡眠模式的时间,以及我的机器处于活动状态的时间。

我能够从上次启动时获得它,但是如果我几天没有关闭系统怎么办?我能得到我在我的机器上花费的活跃时间吗?

也有一种方法,我可以得到我在一个应用程序上花费的时间?示例:我已经安装了Teams、Browser-Chrome和IDE。在给定的时间框架内,我能得到我在应用程序上花费的时间吗?

试试吧。Autoit编写(www.autoitscript.com)当然,你可以通过检查活动窗口标题来扩展它,获取相应的进程,然后计算在特定应用程序上花费的时间,等等。这只是一个开始。

; workstation idle logger for windows
; Functions : IsWorkStationLocked() and IsScreenSaverRunning()
;
#include <Date.au3>
DllOpen("user32.dll")
$actiondate =  _NowCalc()
$timehaspastmin = 0
$timehaspasthour =0
$tmpString1=0
$tmpString2=0
$prediction="was working for"
While 1
$actiontrigger = False
$file = FileOpen("lockstatus.txt", 1)
If $file = -1 Then
MsgBox(0, "Error", "Unable to open file.")
Exit
EndIf
$tmpString1=IsWorkStationLocked()
$tmpString2=IsScreenSaverRunning()
Sleep(10000)
if $tmpString1 <> IsWorkStationLocked() Then
$actiontrigger = True
EndIf
if  $tmpString2 <> IsScreenSaverRunning() Then
$actiontrigger = True
EndIf
if $actiontrigger = True Then
$timehaspastsec = _Datediff ( 's' , $actiondate , _NowCalc())
$timehaspastmin = Round($timehaspastsec / 60,1)
$timehaspasthour = Round($timehaspastmin /60,1)
select
case $timehaspasthour >= 1
$timetype="hour(s)"
$timehaspast=$timehaspasthour
case $timehaspastmin >= 1
$timetype="minute(s)"
$timehaspast=$timehaspastmin
case Else
$timetype="second(s)"
$timehaspast=$timehaspastsec
EndSelect
select
case IsScreenSaverRunning() = False and IsWorkStationLocked() = False
$prediction = "was away for"
case IsScreenSaverRunning() = True and IsWorkStationLocked() = False
$prediction = "was working for"
case IsScreenSaverRunning() = True and IsWorkStationLocked() = True
$prediction = "(really idle now) was watching my screen for "
case IsScreenSaverRunning() = False and IsWorkStationLocked() = True
$prediction = "was working for"
EndSelect
$outputstring =  _NowCalc() & " - " & "scrsaver=" & IsScreenSaverRunning() & ",Locked=" & IsWorkStationLocked() & ", " & $prediction & " " & $timehaspast & " " & $timetype & @CRLF
FileWrite($file , $outputstring )
ConsoleWrite ( $outputstring)
$actiondate =  _NowCalc()
EndIf
FileClose($file)
WEnd
Func IsWorkStationLocked()
Local $Desktop, $Return
$Return = DllCall("user32.dll", "long", "OpenDesktopA", "str", "Default", "dword", 0, "ubyte", 0, "dword", 0x100)
$Desktop = $Return[0]
If $Desktop = 0 Then
Return True
EndIf
$Return = DllCall("user32.dll", "long", "SwitchDesktop", "dword", $Desktop)
DllCall("user32.dll", "long", "CloseDesktop", "dword", $Desktop)
If $Return[0] = 0 Then
Return True
Else
Return False
EndIf
EndFunc
Func IsScreenSaverRunning()
Local $Desktop, $Return, $Result
$Result = DllStructCreate("uint")
$Return = DllCall("user32.dll", "ubyte", "SystemParametersInfoA", "uint", 0x72, "uint", 0, "ptr", DllStructGetPtr($Result), "uint", 0)
If $Return[0] = 0 Then Return SetError( 0, False)
Return DllStructGetData($Result, 1) <> 0
EndFunc

最新更新