I'm trying to understand the difference between the 2 API calls specified in the title.
The only visible difference I've noticed when I tried to mess up with the functions my self was that the CreateProcessWithTokenW()
function adds the process to an isolated job where CreateProcessAsUserA()
s prcoess joins a big group consist of his parnet process, the process created by CreateProcessWithTokenW()
and others. in addistion CreateProcessAsUserA()
require additional privileges in order to succeed, compared with CreateProcessWithTokenW()
function that could run with out them, according to MSDNs documentation the required privileges specified in https://learn.microsoft.com/en-us/windows/win32/api/processthreadsapi/nf-processthreadsapi-createprocessasusera are:
Asked
Active
Viewed 856 times
2

team shmot
- 21
- 1
-
1may be this - https://stackoverflow.com/questions/38427094/createprocessasuser-works-createprocesswithtokenw-does-not/38442543#38442543 can be interesting for you. and also this - https://stackoverflow.com/questions/66226029/windows-create-a-process-in-session-0-using-createprocesswithtokenw/66226619#66226619 – RbMm Oct 21 '21 at 07:45
1 Answers
0
CreateProcessAsUser has been around forever, CreateProcessWithToken was added in Server 2003.
CreateProcessWithToken can load the users profile and deals with the winsta0 windowstation and desktop for you. I believe CreateProcessWithToken requires the secondary logon service to be running.
They require different token permissions so you should probably fall back to the other function if the first fails...

Anders
- 97,548
- 12
- 110
- 164
-
@Andres for my understanding, In the 7th Edition of Windows Internals it actually shows that `CreateProcessWithTokenW` and `CreateProcessWithLogonW` calls the SecLogon.dll and than it calls the `CreateProcessAsUser` which finally calls the `NtCreateUserProcess`, but a direct call to `CreateProcessAsUser` don't, instead it calls the `CreateProcessInternal` before calling the `NtCreateUserProcess`. And I want to understand exactly the need for both of the functions and not just fall back to the other one when the first one fails... – team shmot Oct 21 '21 at 06:59
-
*I believe CreateProcessAsUser requires the secondary logon service to be running* - this is not true. @teamshmot - *CreateProcessWithTokenW* do rpc call to another process and already inside service call `CreateProcessAsUser`. the `CreateProcessAsUser` always execute inside current process – RbMm Oct 21 '21 at 07:40
-
*I believe CreateProcessAsUser requires the secondary logon service to be running* - or sorry, probably you make typo - *I believe **CreateProcessWithToken** requires the secondary logon service to be running* - this is true. yes – RbMm Oct 21 '21 at 07:47