Click here to Skip to main content
14,826,846 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
I want my system to automatically log off user after may 10 minutes of being idle. How do I do that in 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
    End Sub
    Private Sub tim_Tick(ByVal sender As Object, ByVal e As EventArgs)
        Dim lii As LASTINPUTINFO
        lii.cbSize = Len(lii)
        lblCountdown.Text = "You have (secs): " & ((GetTickCount() - lii.dwTime) / 1000.0).ToString
    End Sub
End Class

But the challenge i have it is checking the Windows Idle lather than the my application idle.
Updated 10-Jan-11 3:09am
jerrykid 8-Jan-11 4:27am
auto log off an application or windows system?
Sandeep Mewara 8-Jan-11 4:48am
log-off from website or system?

To logoff:[^]

To detect last windows activity:[^]

A tip I wrote:

The Windows API: Learn It - Live It[^]

And finally, google is your friend.
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.
LloydA111 8-Jan-11 14:35pm
I suppose you could use a keyboard hook to detect keyboard use, but I'm not sure about detecting mouse movement.
Espen Harlinn 8-Jan-11 17:32pm
5+ Good answer - you may have to use interop, interesting ... service control code: SERVICE_CONTROL_SESSIONCHANGE - process will need to be able to access windows station. Register service handler using RegisterServiceCtrlHandlerEx (SERVICE_CONTROL_SESSIONCHANGE not documented for handlers registered using RegisterServiceCtrlHandler ) - doable, flexible - and probably best done in c or c++
Dalek Dave 9-Jan-11 16:54pm
Good Call.
#realJSOP 13-Jan-11 14:42pm
He doesn't need to do that - all he has to do is use the Windows API. See my answer to this question.
fjdiewornncalwe 8-Jan-11 15:07pm
Nice. This link gives a reasonable implementation of the logoff process itself. Now all that is needed is how to detect activity from a service and such.
u hav to config ur config.xml in
Just develop an application which can logoff the system. Change the name app.exe to app.scr. then set app.scr as screen saver & set time 10 mins.
fjdiewornncalwe 8-Jan-11 13:24pm
I just find this to be a horribly impractical solution.
Аslam Iqbal 8-Jan-11 13:47pm
Can't u do that Marcus?
fjdiewornncalwe 8-Jan-11 13:56pm
Excuse me. It is a really bad idea to do this. A user only has to turn off their screensaver to disable what is obviously an administrative function. Your idea is simplistic and poor. Your 1 vote of my solution is extremely silly. However, feel free to expand on your idea and why you think it is a good one. If you have a legitimate criticism of my answer, feel free to share that as well.
Аslam Iqbal 8-Jan-11 14:02pm
Benson didn't mention about security. So I didn't think about that. Your yhought is optimal. But it depends on Besnson's Requirements.
Yusuf 8-Jan-11 14:52pm
screen saver app were never invented to replace executable files. You solution is wrong on many levels
Аslam Iqbal 8-Jan-11 15:05pm
Screen saver is nothing but an executable file. Just copy a scr file (C:\WINDOWS\system32\ssmarque.scr) & rename it to exe & see it has all properties like an exe file. any more Question see binary code of an exe file & a scr file.
See this article from MSDN. It shows "HOW TO: Automatically Log a User Off from a Web Application"
fjdiewornncalwe 8-Jan-11 15:05pm
Sorry Yusuf, but web application logons and system logons are two entirely different things.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900