title: Windows session APIs not loading in time on Windows XP and ways to bypass it
body: <p>I'm writing a service application that needs to enumerate all current user sessions, and obtain their session IDs, and later see what processes are running for what session. I'm using the <code>WTSEnumerateSessions()</code> API, as well as <code>WTSQuerySessionInformation()</code> to obtain a session specific information. Unfortunately those WTS APIs are very unreliable.</p>
  
  <p>On a Windows XP machine with Fast User Switching turned off, or on an XP machine joined to a domain, those APIs are not immediately available. They may fail with the <code>RPC_S_INVALID_BINDING</code>, or 1702, error code for as long as several minutes after the Windows XP boots up and my service starts.</p>
  
  <p>I could not find any official documentation explaining how to handle such limitation. The one available via a search engine is to wait for the terminal services service to load up, which is of course possible, but becomes a <em>MAJOR</em> pain in the a** to implement.</p>
  
  <p>So, if someone could answer the following I'd appreciate it:</p>
  
  <ol>
  <li>Are there any alternative APIs to work with session specific data, that are more reliable that those WTS ones? I mostly need to see current sessions on the machine, get a user name and session status. Also enumerate processes with session IDs for each process. (I know that this is possible, since GINA or a log-in screen, can do all that way before the terminal services load up.)</li>
  <li>Is there a 100% guaratee that WTS-class APIs (such as <code>WTSEnumerateSessions()</code>, <code>WTSQuerySessionInformation()</code> and <code>WTSEnumerateProcesses()</code>) will load up <em>before</em> my service starts up on <em>any</em> version of Windows Vista/Windows 7 machine?</li>
  </ol>
  
  <p>Please note <em>bofore</em> and <em>any</em> stipulations that a VERY important.</p>