I am trying to write a system service that can detect whether th开发者_StackOverflowe 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?
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
精彩评论