I'm on Windows 10 Pro x64 ver 1703 build 15063.726, trying to write a program rebooter service. It runs under my user on admin permissions, every 10 minutes via a scheduled task.
If the server is unavailable or borked:
- if my computer is locked, the rebooter kills and restarts the server program.
- if my computer isn't locked, the rebooter shows a dialog to confirm reboot. I may be doing work on the server program and not want a reboot to ruin any debugging.
The only complication is detecting if the computer is locked. I've tried several methods:
- OpenInputDesktop()
Returns NULL only if the user has started to input their password since the computer was locked. Besides that returns a valid handle. Presumably the input desktop isn't deselected until the user attempts to login and their input switches.
- OpenInputDesktop() vs GetThreadDesktop()
(Passing in GetCurrentThreadID() of course)
Handles still match, probably due to same reason 1 fails.
- Process check for LockApp.exe/LockAppHost.exe
Seems to relate to user inputting their password as well... or because my server rebooter app is 32-bit, having problems reading the 64-bit process LockApp.exe.
- GetForegroundWindow() returns null when locked
While mentioned as dubious, I tried this too. False negative, said it wasn't locked
- Switching desktop manually and seeing if it worked
Described with code example here, this one was also a bust and gave a false negative.
Is there any way left? I'd really rather not have a service just for registering locking/unlocking running constantly.
Or should one of these ways worked already, and my Windows is bugged?
Cheers