How To Logoff My App

Posted on 2008-06-12
Last Modified: 2010-04-30
for Windows Application with vb 2005 , if the user doesn't do any thing with a while say 5 minuets , I want the system to automatically log off.  
Question by:Ahmadal_najjar2003
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 3
LVL 10

Expert Comment

ID: 21781173
* Have 1 global integer variable
* Have a timer that increments this global variable each second by 1
* if the value is higher than 5*60 (ie 300 = 5 minutes), then close application
* For any mouse/keyboard event that is triggered in the application, reset the global variable to 0

Author Comment

ID: 21786202
Ok , How to follow the mouse and keyboard events within the whole application

Author Comment

ID: 21814625
Ok , How to follow the mouse and keyboard events within the whole application
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

LVL 70

Expert Comment

by:Éric Moreau
ID: 21814907
A long time ago (in an old VB6 application) I was having an invisible form with a timer which every half minute was checking for the active form, the active control on that form and the value of that control when possible. If none of those values were modified for 5 minutes (I was checking every 30 seconds) then I was leaving the application. Maybe you can do something like this.

Author Comment

ID: 21815391
It is really a nice Idea , but in some cases give this message
"Object reference not set to an instance of an object"

While My Code Like this

If MyMousePosition = Control.MousePosition And _
           MyActiveForm = ActiveForm.Name And MyActiveControl = ActiveForm.ActiveControl.Name Then

do you have any Idea, Why.

Author Comment

ID: 21815454
After I watch the Error , it belongs to , I feel this happen while I am closing the active form.

Any Suggest
LVL 70

Accepted Solution

Éric Moreau earned 500 total points
ID: 21815626
You can trap it something like this:

    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
        Static sstrPreviousForm As String = String.Empty
        Static sstrPreviousControl As String = String.Empty
        Static sdtmLastAction As DateTime

        Dim strCurrentForm As String
        Dim strCurrentControl As String
            strCurrentForm = ActiveForm.Name
        Catch ex As Exception
            strCurrentForm = String.Empty
        End Try

            strCurrentControl = ActiveForm.ActiveControl.Name
        Catch ex As Exception
            strCurrentControl = String.Empty
        End Try

        If (strCurrentForm <> sstrPreviousForm) OrElse (strCurrentControl <> sstrPreviousControl) Then
            sstrPreviousForm = strCurrentForm
            sstrPreviousControl = strCurrentControl
            sdtmLastAction = Date.Now
            Label1.Text = sstrPreviousForm
            Label2.Text = sstrPreviousControl
        End If
        Label3.Text = DateDiff(DateInterval.Minute, sdtmLastAction, Date.Now).ToString ' Date.Now.ToLongTimeString

        If DateDiff(DateInterval.Minute, sdtmLastAction, Date.Now) > 5 Then Application.Exit()
    End Sub

Author Comment

ID: 21816041
Thats Very Nice .

Thank You Very Much. But I need from you one thing if you can. You Use static inside the timer
is this mean just for the first time when fired just assign string.empty value . then after that will keep the value which which assign later. If you can help me for the lifetime and visibilty of this .

LVL 70

Expert Comment

by:Éric Moreau
ID: 21816118
Static variables have the lifetime of the class (form) in which it is found but they are only visible from within the method.

Author Closing Comment

ID: 31466784
Thank You a lot

Featured Post


Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Suggested Courses
Course of the Month4 days, 5 hours left to enroll

630 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question