//将该出发语句放main方法下,触发。
SystemEvents.SessionEnding += new SessionEndingEventHandler(SystemEvents_SessionEnding);
private static void SystemEvents_SessionEnding(object sender, SessionEndingEventArgs e)
{
SessionEndReasons reason = e.Reason;
switch (reason)
{
case SessionEndReasons.Logoff:
//MessageBox.Show("用户正在注销。操作系统继续运行,但启动此应用程序的用户正在注销。");
break;
case SessionEndReasons.SystemShutdown:
//MessageBox.Show("操作系统正在关闭。");
...
...
break;
}
}