Click here to Skip to main content
14,238,693 members
Rate this:
Please Sign up or sign in to vote.
See more:
I don't have any experience in WINAPI. I'm using visual c++ to create a service. I have a service which creates a process(notepad.exe) under the SYSTEM account. This service has to launch the process under the user account(currently logged on user account). 

What I have tried:

1.Get the process_id of a process(OneDrive.exe or explorer.exe) which is ran by a logged on user.

2.Use processHandle = OpenProcess(PROCESS_ALL_ACCESS,TRUE,process_id) function to get the handle to the process.

3.Use OpenProcessToken(processHandle , TOKEN_QUERY | TOKEN_IMPERSONATE | TOKEN_DUPLICATE, hToken) to get a user token.(I can get the token, but I don't know whether this token is valid or not!)

4.Then use ImpersonateLoggedOnUser(hToken) function to create the process under the user account.(this step always fails in my case)

Can anyone please help me to get out from this issue...??
CHill60 19-Jun-19 10:59am
"this step always fails in my case" - silently or do you get an error message in the event log?
Also - is this article of any use [Security] - User Impersonation[^]
Member 14490792 26-Jun-19 5:09am
Thanks dude...

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100