如何追踪.exe文件运行时长及Unity关联工作时间统计方案问询
Hey there, let's tackle your two questions one by one with practical, actionable solutions:
Here are reliable methods covering native tools, scripts, and lightweight third-party options:
PowerShell Script Monitoring
You can write a simple script to track when the target .exe starts and stops, then calculate total runtime. ReplaceTarget.exewith your program name:$processName = "Target.exe" $startTime = $null while ($true) { $process = Get-Process -Name $processName -ErrorAction SilentlyContinue if ($process -and !$startTime) { $startTime = Get-Date Write-Host "$processName started at $startTime" } elseif (!$process -and $startTime) { $endTime = Get-Date $duration = $endTime - $startTime Write-Host "$processName stopped. Total runtime: $($duration.Hours)h $($duration.Minutes)m $($duration.Seconds)s" $startTime = $null } Start-Sleep -Seconds 5 }Run it in PowerShell, and it will automatically log the total runtime once the process exits.
Windows Event Viewer
Windows' built-in event logs track process creation and termination. Open Event Viewer → navigate toWindows Logs > Security, then filter for event IDs 4688 (process creation) and 4689 (process exit). Add a filter for your target .exe name, find matching start/stop events, and calculate the time difference between them.Lightweight Third-Party Tools
- Process Monitor (Sysinternals) : Set a filter for
Process Name is Target.exe, then track "Process Start" and "Process Exit" events. Export the log to calculate total runtime. - TimeSnapper : A tool that tracks process runtime and takes periodic screenshots. You can directly view cumulative runtime for your target .exe in its process list.
- Process Monitor (Sysinternals) : Set a filter for
I get your frustration—standard tools only count active window time, leaving out research time that's still part of your Unity workflow. Here's how to fix this:
Customize ManicTime Activity Groups
ManicTime lets you group related activities, so you can merge Unity and Chrome's Unity-focused windows into one tracked category:- Open ManicTime and go to the
Activitiestab. - Click
New Groupand name it "Unity Work". - Add two rules to the group:
- Rule 1:
Process is Unity.exe(matches the Unity editor) - Rule 2:
Window title contains Unity(matches Chrome tabs with Unity in the title, like search results for "Unity character movement")
- Rule 1:
- Now ManicTime will automatically combine time spent in Unity and relevant Chrome tabs under the "Unity Work" group.
- Open ManicTime and go to the
AutoHotkey Script for Automated Tracking
For full customization, use AutoHotkey to build a script that tracks time when Unity is running and you're on Unity-related Chrome pages:global isUnityRunning := false global totalWorkTime := 0 global activeStartTime := 0 Loop { ; Check if Unity is running Process, Exist, Unity.exe if (ErrorLevel) { isUnityRunning := true WinGetTitle, activeTitle, A ; Track time if on Unity or Unity-related Chrome tab if (activeTitle contains "Unity" || activeTitle contains "unity") { if (activeStartTime = 0) { activeStartTime := A_TickCount } } else { ; Stop and accumulate time when switching away if (activeStartTime != 0) { totalWorkTime += A_TickCount - activeStartTime activeStartTime := 0 } } } else { ; Show total time when Unity closes if (isUnityRunning) { if (activeStartTime != 0) { totalWorkTime += A_TickCount - activeStartTime activeStartTime := 0 } totalMinutes := Round(totalWorkTime / 1000 / 60, 2) MsgBox, Total Unity work time (including Chrome research): %totalMinutes% minutes ; Reset for next session totalWorkTime := 0 isUnityRunning := false } } Sleep, 1000 }Run this script, and it will automatically track eligible time while Unity is open, then show the total when you close Unity.
RescueTime Custom Categories
RescueTime lets you categorize activities by process and website. Create a "Unity Development" category and add rules for:- The
Unity.exeprocess - Unity-related websites like
*.unity.com,stackoverflow.com/tagged/unity3d, andforum.unity.com
It will then merge all these activities into one total for your Unity workflow.
- The
内容的提问来源于stack exchange,提问作者serdar efe

