title: Running program as another user
body: <p>I'm trying to launch an application as another user in my program. Here's what my code looks like:  </p>
  
  <pre><code>result = CreateProcessWithLogonW(username.c_str(),domain.c_str() , password.c_str(),
               LOGON_NETCREDENTIALS_ONLY, exePath.c_str() ,NULL, 0, NULL, NULL, &amp;su_info, &amp;pi);
  </code></pre>
  
  <p>This works perfectly fine. However I noticed when when I run my program using this method (<code>LOGON_NETCREDENTIALS_ONLY</code>) and look at my program in task manager it is shown to be run as the calling process not the user I expected. There are actually other problems with this kind of logon but to keep it simple let's focus on task manager behavior. So in order to fix this problem I changed the logon flags to <code>LOGON_WITH_PROFILE</code>:  </p>
  
  <pre><code>result = CreateProcessWithLogonW(username.c_str(),domain.c_str() , password.c_str(),
               LOGON_WITH_PROFILE, exePath.c_str() ,NULL, 0, NULL, NULL, &amp;su_info, &amp;pi);
  </code></pre>
  
  <p>But now I creating process fails and error code 1326 (The user name or password is incorrect) is returned.<br>
  Why is this happening? How do I run my executable as another user and actually see it being run as that user even in the task manager?  </p>
  
  <p><strong>EDIT:</strong><br>
  More debugging showed that the program works fine if I run the program normally. However if I run my program as post-build event (to run my tests) this type of logon fails.</p>