title: CreateProcessAsUser doesn't work in windows service
body: <p>I wanted to make a windows service in c++ to start my programs as administrator every time the user log in without pop up UAC window</p>
  
  <p>As it's the first time for me to do it I used the project from here :
  <a href="https://code.msdn.microsoft.com/windowsapps/CppWindowsService-cacf4948/view/SourceCode" rel="nofollow noreferrer">https://code.msdn.microsoft.com/windowsapps/CppWindowsService-cacf4948/view/SourceCode</a></p>
  
  <p>I edited line 74 in CppWindowsService.cpp  to this :</p>
  
  <pre><code>InstallService(
              SERVICE_NAME,               // Name of service
              SERVICE_DISPLAY_NAME,       // Name to display
              SERVICE_AUTO_START,         // Service start type
              SERVICE_DEPENDENCIES,       // Dependencies
              0,            // Service running account
              SERVICE_PASSWORD            // Password of the account
              );
  </code></pre>
  
  <p>and added some code to the worker thread in SampleService.cpp line 101 to become like this :</p>
  
  <pre><code>void CSampleService::ServiceWorkerThread(void)
  {
  // Periodically check if the service is stopping.
  while (!m_fStopping)
  {
      // Perform main service function here...
  
      HANDLE hToken = NULL, dToken;
      WTSQueryUserToken(WTSGetActiveConsoleSessionId(), &amp;hToken);
      DuplicateTokenEx(hToken, MAXIMUM_ALLOWED, 0, SecurityIdentification, TokenPrimary, &amp;dToken);
      STARTUPINFO stinfo = { 0 };
      PROCESS_INFORMATION pinfo = { 0 };
      stinfo.cb = sizeof(stinfo);
      stinfo.lpDesktop = L"winsta0\\default";
      LPVOID pEnv = 0;
      CreateEnvironmentBlock(&amp;pEnv, dToken, 0);
      CreateProcessAsUserW(dToken, L"F:\\test.exe",0, 0, 0, 0,CREATE_NEW_CONSOLE, pEnv, 0, &amp;stinfo, &amp;pinfo);
  
      ::Sleep(2000);  // Simulate some lengthy operations.
  }
  
  // Signal the stopped event.
  SetEvent(m_hStoppedEvent);
  }
  </code></pre>
  
  <p>the test.exe located in F drive shows a message box but when I try to run it from a service nothing happen although I can easily use CreateProcess to execute it from ordinary programs</p>
  
  <p>Edit : I also tried put a command line in CreateProcessAsUser but nothing happens</p>