According to numerous MS rep posts there is no way to do this in XP. In reality you just need to determine what logon is actuated on session 0 and see if they are "active" or not. This isn't an official answer but since XP updates are being phased out and this method still seems to be valid I'd say you're golden.
I'm over thinking this, the issue you're having is that service stations don't have an input desktop so that's why "OpenInputDesktop()" is always going to return 'NULL'. Have you actually tried switching your process to 'WinSta0' yet? You may need to make it into a separate application.
Not sure what you mean sorry. My application runs as a service (system user) which it is required to for other reasons. The OS is standard Windows XP and I'm trying to avoid creating any other applications etc. to implement this capability.
// produces a pointer
pointer = User32.OpenWindowStation("winsta0", false, MAXIMUM_ALLOWED);
// this returns true so appears to work
value = User32.SetProcessWindowStation(pointer);
// correctly returns null when ran as a user and the station is locked.
// incorrectly always returns a valid handle when run as system user.
if (User32.OpenInputDesktop(0, false, 0x0001)==null) {
// Station is locked
}
The open window station returns a valid handle and the setprocesswindowstation returns true but I am still getting the same behaviour. When ran as the logged in user openinputdesktop return false when the station is locked and when ran as a service (system user) I always get a valid handle.
Now that I think about it this is because there will always be a 'winsta0' for it to connect to.
I've got to be honest. I've never liked the method that I suggested earlier, seeing if the logged on user is idle, but this one really has me stumped. The cop out answer is to leave your remote service running and have it keep a tally of the number of times it recieves the 'WM_WTSSESSION_CHANGE' message with a wParam argument of 'WTS_SESSION_LOCK' vs the number of times it recieves that message with a wParam argument of 'WTS_SESSION_UNLOCK'. But I'm sure that is not really helpful for you. Unfortunatly I don't have a better answer for you when running on XP. Here is a link to that message: http://msdn.microsoft.com/en-us/library/windows/desktop/aa383828(v=vs.85).aspx