none
Windows Service That logs System Idle Time.

    Question

  • Hi

    I am trying to develop project which includes a Windows Service Capable of logging the System Idle Time.
    The Windows Service Should log system idle time even after the user has logged off and hence the service runs in the local system account.

    The Service Works perfectly fine when installed and run in Windows XP ..  but when run inside a service in Windows Vista it does not return the Idle time. but only the system Uptime. It code works fine in windows vista when run as a windows application too.
    My guess is that vista does not allow the detection of mouse/ keyboard movements.  Please let me know if there is a work around to this problem...

    Following is the code in vb.net that is used for calculating idletime

    'CLASS TO OBTAIN IDLE TIME

    Imports System.Runtime.InteropServices

    Public Class IdleTime

        Private Declare Function GetLastInputInfo Lib "User32.dll" _
          (ByRef lastInput As LASTINPUTINFO) As Boolean

        <StructLayout(LayoutKind.Sequential)> _
        Public Structure LASTINPUTINFO
            Public cbSize As Int32
            Public dwTime As Int32
        End Structure


          Public Shared ReadOnly Property IdleTime() As Integer

            Get

                Dim lastInput As New LASTINPUTINFO

                lastInput.cbSize = Marshal.SizeOf(lastInput)

                If GetLastInputInfo(lastInput) Then

                    Return (Environment.TickCount - lastInput.dwTime) / 1000

                End If

            End Get

        End Property


    End Class


    ***********************

    Thanks in Advance
    Aaron
    Saturday, July 04, 2009 6:39 AM

Answers

  • Hmya, why are you posting VB.NET code in a C# forum?  Your hang-up is Vista's session 0 isolation , you can't make it work on Vista.  Or Win7.  Good news to the people you are trying to monitor, no doubt.  Security works both ways.

    Hans Passant.
    • Marked as answer by Figo Fei Thursday, July 09, 2009 3:27 AM
    Sunday, July 05, 2009 10:28 PM

All replies

  • Hmya, why are you posting VB.NET code in a C# forum?  Your hang-up is Vista's session 0 isolation , you can't make it work on Vista.  Or Win7.  Good news to the people you are trying to monitor, no doubt.  Security works both ways.

    Hans Passant.
    • Marked as answer by Figo Fei Thursday, July 09, 2009 3:27 AM
    Sunday, July 05, 2009 10:28 PM
  • Thanks Hans

    Its the first time Im posting in this forum.. Reply was really quick... I had been trying for days to work out something to solve this. Is there anything that i can do to find the idle time during session logout ? Or does the Vista security feature block all attempts? ( Considering development in any programming language).

    Aaron Dias 
    Thursday, July 09, 2009 5:38 AM