您的位置:首页 > 理论基础

C#如何获得计算机的登录、注销、锁定等状态

2016-06-17 10:23 330 查看
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();

SystemEvents.SessionSwitch += new SessionSwitchEventHandler(SystemEvents_SessionSwitch);
}

~Form1()
{
//Do this during application close to avoid handle leak
Microsoft.Win32.SystemEvents.SessionSwitch -= new SessionSwitchEventHandler(SystemEvents_SessionSwitch);
}

void SystemEvents_SessionSwitch(object sender, SessionSwitchEventArgs e)
{
switch (e.Reason)
{
case SessionSwitchReason.SessionLogon:
case SessionSwitchReason.SessionUnlock:
MessageBox.Show("没有锁住");
break;

case SessionSwitchReason.SessionLock:
MessageBox.Show("锁住");
break;
case SessionSwitchReason.SessionLogoff:

break;
}
}

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: