想知道電腦確切開機時間、對比不同時期啟動速度、排查不明原因重啟?Windows 7 內建「事件檢視器」記錄了詳細的系統啟動/關機事件,無需第三方軟體即可精確查詢。本文提供圖文並茂的完整操作指南。
以系統管理員身分開啟「命令提示字元」或 PowerShell:
wevtutil qe System /q:"*[System[(EventID=6005)]]" /c:10 /rd:true /f:text | findstr "TimeCreated"
輸出範例:
TimeCreated[SystemTime]: 2024-01-15T08:30:45.123Z
TimeCreated[SystemTime]: 2024-01-14T07:55:12.456Z
...
wevtutil qe System /q:"*[System[(EventID=6006)]]" /c:10 /rd:true /f:text | findstr "TimeCreated"
Get-WinEvent -FilterHashtable @{LogName='System'; ID=6005; StartTime=(Get-Date).AddDays(-30)} |
Select-Object TimeCreated, Id, LevelDisplayName, Message |
Format-Table -AutoSize
可導出 CSV:`... | Export-Csv -Path C:\BootTimes.csv -NoTypeInformation`。
事件檢視器僅給出「啟動完成」時間點。若需分析 **BIOS POST、載入驅動、服務啟動、Explorer 啟動** 各階段耗時,請使用 **Windows Performance Toolkit (WPT)**:
xbootmgr -trace boot -traceFlags BASE+CSWITCH+DRIVERS+POWER -resultPath C:\BootTrace -noPrepReboot -postBootDelay 120| 事件 ID | 來源 | 意義 |
|---|---|---|
| 6005 | EventLog | 事件記錄服務啟動 —— **系統啟動完成** |
| 6006 | EventLog | 事件記錄服務停止 —— **系統關機開始** |
| 6008 | EventLog | 上一次關機非預期 (藍屏、斷電、死機強制關機) |
| 6009 | EventLog | 作業系統版本資訊 (啟動時記錄) |
| 6013 | EventLog | 系統運作時間 (每日記錄一次) |
| 1074 | User32 | 使用者/應用程式發起關機/重啟 (含原因代碼) |
| 1076 | User32 | 關機原因註解 |
| 41 | Kernel-Power | 系統未正常關機就重新啟動 (斷電/死機/重置) |
| 12, 13 | Kernel-General | 核心啟動/關機階段詳細資訊 (需啟用分析通道) |
建立 `LogBootShutdown.ps1`,設定工作排程器「登入時」/「事件 6005/6006 觸發」執行:
$logPath = "C:\Logs\BootShutdown.csv"
$event = Get-WinEvent -FilterHashtable @{LogName='System'; ID=6005,6006} -MaxEvents 1
$type = if ($event.Id -eq 6005) { 'Boot' } else { 'Shutdown' }
$line = "$(Get-Date -Format 'yyyy-MM-dd HH:mm:ss'),$type,$($event.TimeCreated)"
if (-not (Test-Path $logPath)) { "DateTime,Type,EventTime" | Out-File -Encoding utf8 $logPath }
Add-Content -Path $logPath -Value $line -Encoding utf8
長期累積即可生成開機趨勢圖,量化優化成果。
善用事件檢視器與 WPT,將「感覺開機慢」轉化為「開機從 45 秒優化至 18 秒、主要瓶頸在 XXX 驅動延遲 3 秒」的具體工程數據。數據驅動優化,才是專業運維的態度!