用户注销时会引发哪个系统事件 [英] which event of system is raised when user logoff

查看:54
本文介绍了用户注销时会引发哪个系统事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨那里用
i在c#中创建一个windows服务。

i必须检测用户何时从系统注销。

i认为解决方案是找到第一个系统事件沿着用户注销操作。

请指导我。

谢谢

解决方案

会话结束您可以处理关闭或注销的事件



 使用 Microsoft .Win32; 

// 你需要在服务开始时初始化
SystemEvents.SessionEnding + =
new SessionEndingEventHandler(SystemEvents_SessionEnding);


void SystemEvents_SessionEnding( object sender,SessionEndingEventArgs e)
{
if (Environment.HasShutdownStarted)
{
// 处理关闭
}
else
{
// 处理注销
}
}


hi there
i create a windows service in c#.
i must detect when user logoff from system.
i think solution is finding the first event of system along user logoff operation.
please guide me.
thanks

解决方案

There is Session ending event in which you can handle shutdown or log off

using Microsoft.Win32;

 // you need to init this on service start
 SystemEvents.SessionEnding += 
            new SessionEndingEventHandler(SystemEvents_SessionEnding);


 void SystemEvents_SessionEnding(object sender, SessionEndingEventArgs e)
 {
     if (Environment.HasShutdownStarted)
     {
         //Handle shutdown
     }
     else
     {
         //Handle log off
     }
  }


这篇关于用户注销时会引发哪个系统事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆