Windows 7 - 如果發生事件則顯示訊息

Windows 7 - 如果發生事件則顯示訊息

我希望在事件 7026 發生時收到訊息。 (7026 = 驅動程式載入失敗)但我無法為此目的建立工作任務。在事件上建立任務(在事件檢視器中右鍵單擊所選事件,然後將任務附加到此事件...)不起作用。

有沒有辦法透過一項任務來做到這一點?

答案1

您可以在啟動時執行類似以下內容的批次檔:

@echo off
set evtid=7026
set timepd=30000
for /f %%a in ('wevtutil qe System /rd:true /f:text "/q:*[System[(EventID=%evtid%) and TimeCreated[timediff(@SystemTime) <= %timepd%]]]" ^| find /c "%evtid%"') do set evtcnt=%%a
if %evtcnt% gtr 0 (
    echo WScript.Echo "Event %evtid% occurred %evtcnt% time(s) in the last " ^& ^(%timepd%/1000^) ^& " seconds!" > Msg.vbs
) else (
    echo WScript.Echo "Event %evtid% did not occur even once in the last " ^& ^(%timepd%/1000^) ^& " seconds!" > Msg.vbs
)
wscript Msg.vbs
del Msg.vbs

它使用韋夫圖爾命令列實用程式來查詢系統過去 30 秒內事件 7026 的所有實例的事件日誌。

相關內容