2

I need to understand the use of lpEnvironment in CreateProcessAsUser.

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

CreateProcessAsUser(hTokenCpy, null, applicationName, ref saProcess, ref saThread, false, CREATE_UNICODE_ENVIRONMENT, hEnv, null, ref si, out procInfo)

which is called after calling this

CreateEnvironmentBlock(out hEnv, hTokenCpy, false) || hEnv == IntPtr.Zero)

However if the call to CreateProcessAsUser fails.

Another attempt is made by passing hEnv/IpEnvironment = 0

CreateProcessAsUser(hTokenCpy, null, applicationName, ref saProcess, ref saThread, false, 0, IntPtr.Zero, null, ref si, out procInfo

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.

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

Ranjeeth
  • 91
  • 1
  • 9
  • Same issue here, will reply if I discover the answer. – tommed Jul 02 '16 at 17:11
  • @tommed Any news? – manuell Mar 23 '17 at 13:40
  • It has been a while and I concluded at that time that it is because the process is getting created under the memory block of the windows service. For win 7 > OS you don't need to make a call using hEnv/IpEnvironment = 0 since they are 64 bit OS i guess. And also we decided not to support XP based devices – Ranjeeth Dec 21 '17 at 18:07

0 Answers0