title: How to get an 'Active Session ID' in a windows server OS?
body: <p>I need to execute my application without user interaction at machine start up. I need this to run in all Windows XP, Windows Vista, Windows Server 2003, Windows 7 and Windows Server 2008 OSs.
  <br/><br/>
  For this, I followed these steps,</p>
  
  <ol>
  <li>Get active session id using <b>WTSGetActiveConsoleSessionId</b></li>
  <li>Obtain the process id of the winlogon process that is running within the currently active session</li>
  <li>Obtain a handle to the winlogon process</li>
  <li>Obtain a handle to the access token of the winlogon process using <b>OpenProcessToken</b></li>
  <li>Duplicate the access token of the winlogon process <b>DuplicateTokenEx</b></li>
  <li>Create a new process in interactive window station and in the current user's logon session using <b>CreateProcessAsUser</b></li>
  <li>And then close all handles.</li>
  </ol>
  
  <p>And it works for all Workstations and when the Servers have an active console id running. It's pretty obvious because in step 1 I catch the Active Console Id. I found some other ways to start my applications in OSs before Windows Session 0 Isolation was introduced.</p>
  
  <p>Now I need to catch whether <b>WTSGetActiveConsoleSessionId</b> has returned a valid id and if not create a new session and start my application in it or catch an active RDP session an run my application in it or show the logged in users screen for the user to decide (which would be ideal since my application is a screen capturing one). I'm sure their should be a way to do this, and I need your help for this.
  <br/><br/>Thanks a lot!</p>