title: Check if Windows is currently locked
body: <p>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.</p>
  
  <p>If the server is unavailable or borked:</p>
  
  <ul>
  <li>if my computer is locked, the rebooter kills and restarts the server program.</li>
  <li>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.</li>
  </ul>
  
  <p>The only complication is detecting if the computer is locked. I've tried several methods:</p>
  
  <ol>
  <li>OpenInputDesktop()</li>
  </ol>
  
  <p>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.</p>
  
  <ol start="2">
  <li>OpenInputDesktop() vs GetThreadDesktop()</li>
  </ol>
  
  <p>(Passing in GetCurrentThreadID() of course)</p>
  
  <p>Handles still match, probably due to same reason 1 fails.</p>
  
  <ol start="3">
  <li>Process check for LockApp.exe/LockAppHost.exe</li>
  </ol>
  
  <p>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.</p>
  
  <ol start="4">
  <li>GetForegroundWindow() returns null when locked</li>
  </ol>
  
  <p>While <a href="https://stackoverflow.com/questions/3953297/detecting-if-the-screensaver-is-active-and-or-the-user-has-locked-the-screen-in">mentioned as dubious</a>, I tried this too. False negative, said it wasn't locked</p>
  
  <ol start="5">
  <li>Switching desktop manually and seeing if it worked</li>
  </ol>
  
  <p>Described with code example <a href="https://stackoverflow.com/a/9858981">here</a>, this one was also a bust and gave a false negative.</p>
  
  <p>Is there any way left? I'd really rather not have a service just for registering locking/unlocking running constantly.</p>
  
  <p>Or should one of these ways worked already, and my Windows is bugged?</p>
  
  <p>Cheers</p>