自动注销 [英] Auto Log-off
本文介绍了自动注销的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我希望系统在闲置10分钟后自动注销用户.如何在vb.net中做到这一点?.桌面应用程序
我正在使用此代码:
I want my system to automatically log off user after may 10 minutes of being idle. How do I do that in vb.net?.Desktop application
Am Using this code:
Private Declare Function GetLastInputInfo Lib "user32" (ByRef plii As LASTINPUTINFO) As Boolean
Private Declare Function GetTickCount Lib "kernel32" () As Int32
Private Sub frmAutoLogout_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim tim As New Timer
tim.Interval = 200
AddHandler tim.Tick, AddressOf tim_Tick
tim.Start()
End Sub
Private Sub tim_Tick(ByVal sender As Object, ByVal e As EventArgs)
Dim lii As LASTINPUTINFO
lii.cbSize = Len(lii)
GetLastInputInfo(lii)
lblCountdown.Text = "You have (secs): " & ((GetTickCount() - lii.dwTime) / 1000.0).ToString
End Sub
End Class
但是我面临的挑战是检查Windows Idle而不是我的应用程序空闲.
But the challenge i have it is checking the Windows Idle lather than the my application idle.
推荐答案
要注销:
http://pinvoke.net/default.aspx/user32.ExitWindowsEx [ http://pinvoke.net/default.aspx/user32.GetLastInputInfo# [ Windows API:学习-直播 [ ^ ]
最后,谷歌是您的朋友.
To logoff:
http://pinvoke.net/default.aspx/user32.ExitWindowsEx[^]
To detect last windows activity:
http://pinvoke.net/default.aspx/user32.GetLastInputInfo#[^]
A tip I wrote:
The Windows API: Learn It - Live It[^]
And finally, google is your friend.
如果您希望它作为系统中的后台服务运行,则可以编写Windows Service来实现.我不知道如何检测用户是在使用系统还是在闲置.
If you want this to run as a background service in the system, you can perhaps write a Windows Service to achieve this. How to detect whether the user is using the system, or whether it is idle, I do not know.
^ ]
这篇关于自动注销的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文