Use of lpEnvironment in CreateProcessAsUser
<p>I need to understand the use of lpEnvironment  in CreateProcessAsUser.</p>

<p>I have these two lines of code in my solution which in invoked by a windows service running as Local System.</p>

<blockquote>
  <p>CreateProcessAsUser(hTokenCpy, null, applicationName, ref saProcess, ref saThread, false, CREATE_UNICODE_ENVIRONMENT, hEnv, null, ref si, out procInfo)</p>
</blockquote>

<p>which is called after calling this</p>

<blockquote>
  <p>CreateEnvironmentBlock(out hEnv, hTokenCpy, false) || hEnv == IntPtr.Zero)</p>
</blockquote>

<p>However if the call to CreateProcessAsUser fails. </p>

<p>Another attempt is made by passing hEnv/IpEnvironment  = 0 </p>

<blockquote>
  <p>CreateProcessAsUser(hTokenCpy, null, applicationName, ref saProcess, ref saThread, false, 0, IntPtr.Zero, null, ref si, out procInfo</p>
</blockquote>

<p>However when the process is created under a specific user name the created process fails to interact with the desktop. Even though the logon user and the user under which the process is running are same.</p>

<p>Is this because the process is getting created under the memory block of the Windows service instead of the logged on User ? </p>