Executing a batch script on Windows shutdown

前端 未结 6 629
旧巷少年郎
旧巷少年郎 2020-12-08 06:55

Is there any way, in Windows 7 Professional, to run a batch script (e.g., a .BAT file) when the user clicks on \"shutdown\" (not a batch file scheduled to shut

6条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-08 07:43

    Programatically this can be achieved with SCHTASKS:

    SCHTASKS /Create /SC ONEVENT /mo "Event[System[(EventID=1074)]]" /EC Security /tn on_shutdown_normal /tr "c:\some.bat" 
    
    SCHTASKS /Create /SC ONEVENT /mo "Event[System[(EventID=6006)]]" /EC Security /tn on_shutdown_6006 /tr "c:\some.bat" 
    
    SCHTASKS /Create /SC ONEVENT /mo "Event[System[(EventID=6008)]]" /EC Security /tn on_shutdown_6008 /tr "c:\some.bat" 
    

提交回复
热议问题