title: CreateProcessWithLogonW and mmc.exe
body: <p>I wrote a program, that should work like RunAs. It works fine, but i have one problem with it. If i want to run for example compmgmt.msc, then i should run mmc.exe and compmgmt.msc as it's parameter. Computer Management will open, but not under the user as i want to run it. It will run under that username who is logged in. Can someone tell me why is that, and how can i correct it? Here is my code : </p>
  
  <pre><code>void createproc(
           wchar_t * user, 
           wchar_t * domain, 
           wchar_t * pass, 
           wchar_t * applicationname)
  {
      int errorcode; 
      char cmd[Buf_Size];
  
      STARTUPINFO StartInfo;
      PROCESS_INFORMATION ProcInfo;
      memset(&amp;ProcInfo, 0, sizeof(ProcInfo));
      memset(&amp;StartInfo, 0 , sizeof(StartInfo)); 
      StartInfo.cb = sizeof(StartInfo); 
      StartInfo.wShowWindow = SW_HIDE; 
  
      int bFuncRetn =
       CreateProcessWithLogonW
       (
          user,
          domain,
          pass,
          LOGON_NETCREDENTIALS_ONLY,
          L"C:\\Windows\\System32\\mmc.exe", //applicationname,
          L" compmgmt.msc",
          CREATE_UNICODE_ENVIRONMENT,
          NULL,
          NULL,
          (LPSTARTUPINFOW)&amp;StartInfo,
          &amp;ProcInfo
       );
  
      errorcode = GetLastError();
  
      if ( bFuncRetn == 0 ) 
      {
         CloseHandle(ProcInfo.hProcess); 
         CloseHandle(ProcInfo.hThread); 
         printf("\nGetLastError :: %d CreateProcessWithLogonW Failed!", 
             errorcode);
         printf("\nFor more information type :: Net Helpmsg %d", 
             errorcode);
         getch();
         exit(1);
      }
  
      CloseHandle(ProcInfo.hProcess); 
      CloseHandle(ProcInfo.hThread); 
  
  }//createproc
  </code></pre>
  
  <p>Thanks for your help!</p>
  
  <p>kampi</p>