如何检测工作站锁 [英] How to detect a workstation lock
本文介绍了如何检测工作站锁的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在开发应用程序,并且试图检测工作站何时被锁定,例如通过用户按下Windows + L键.
I'm developing an application and I'm trying to detect when the workstation gets locked, for example by the user pressing the Windows + L keys.
我知道lock事件具有值
I know that the lock event has the value
WTS_SESSION_LOCK 0x7
但是我不知道如何使用它.我已经在网上搜索了,但一无所获.
But i don't know how to use it. I've searched the web but found nothing.
推荐答案
最终在VB上成功做到了:D
Finnallly managed to do it on VB :D
首先,您需要导入库:
Imports System
Imports Microsoft.Win32
Imports System.Windows.Forms
然后添加处理程序:
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
AddHandler SystemEvents.SessionSwitch, AddressOf SessionSwitch_Event
End Sub
最后,创建捕获它的子项:
Finnally you create the sub that captures it:
Private Sub SessionSwitch_Event(ByVal sender As Object, ByVal e As SessionSwitchEventArgs)
If e.Reason = SessionSwitchReason.SessionLock Then
MsgBox("Locked")
End If
If e.Reason = SessionSwitchReason.SessionUnlock Then
MsgBox("Unlocked")
End If
End Sub
最后一次删除处理程序:
Last you remove the handler:
Private Sub closing_event(sender As Object, e As FormClosingEventArgs) Handles MyBase.FormClosing
RemoveHandler SystemEvents.SessionSwitch, AddressOf SessionSwitch_Event
End Sub
这篇关于如何检测工作站锁的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文