.NET在Windows 10中检测登录事件 [英] .NET Detecting a Logon event in Windows 10

查看:64
本文介绍了.NET在Windows 10中检测登录事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在这个问题上有些困惑.我需要检测用户何时登录,何时锁定显示屏以及用户何时注销.过去,我曾使用过VB.NET应用程序,该应用程序使用对Sens(系统事件通知服务)的COM引用,该引用利用了Sens Events ISensLogon接口.

I've been getting a little stumped on this issue. I have a need to detect when a user logs on, when the Display is Locked, and when the user logs off. In the past I've used a VB.NET application which uses a COM reference to Sens ( System Event Notification Service ) which makes use of the Sens Events ISensLogon interface.

但是,由于移至Windows 10,因此我不再能够将Sens作为COM对象添加到我的项目中.我是否缺少使用此功能的SDK?

However, since moving to windows 10, I'm no longer able to add Sens as a COM object to my project. Is there an SDK that I'm missing in order to make use of this functionality?

在Windows 10中是否需要使用另一个COM库或引用来检测这些事件?

Is there another COM library or reference that I need to use in order to detect these events in Windows 10?

推荐答案

尝试一下:

Imports Microsoft.Win32

Public Class Form1
    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
    AddHandler SystemEvents.SessionSwitch, AddressOf SystemEvents_SessionSwitch
End Sub

Private Sub SystemEvents_SessionSwitch(sender As Object, e As SessionSwitchEventArgs)

    Select Case e.Reason
        Case SessionSwitchReason.SessionLock
            MessageBox.Show("Lock")
        Case SessionSwitchReason.SessionLogoff
            MessageBox.Show("LogOff")
        Case SessionSwitchReason.SessionLogon
            MessageBox.Show("Login")
        Case SessionSwitchReason.SessionUnlock
            MessageBox.Show("Unlock")
        Case Else
    End Select

End Sub

End Class

在.NET框架使之成为可能的情况下,尝试远离COM.

Try to stay out of COM when and where the .NET framework makes that possible.

这篇关于.NET在Windows 10中检测登录事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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