I am trying to write a system service that can detect whether the user is active and then launch a process if not. I am using a service because I want this to work if the user is logged in or not. I have been trying to hook into the user32.dll API and retrieve the time since last user input. However the integer being returned is always 0 so I don't think it is working correctly. Is this not possible when running as a system service?

link|flag

1 Answer

You may like to use getlastinputinfo on user32.dll

<DllImport("user32.dll")> _
Shared Function GetLastInputInfo(ByRef plii As LASTINPUTINFO) As Boolean
End Function

<StructLayout(LayoutKind.Sequential)> _
    Structure LASTINPUTINFO
    <MarshalAs(UnmanagedType.U4)> _
    Public cbSize As Integer
    <MarshalAs(UnmanagedType.U4)> _
    Public dwTime As Integer
End Structure

LASTINPUTINFO on MSDN

link|flag

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.