Terminating Process Error "Access Denied"
-
Hi all i have a code where i am starting the process from a windows service that i created. Now i want to terminate that process using some other application(MFC stand alone) application. But when ever i try to do that,it gives error 5 which documentation says is "Error Access Denied"......here r the codes that i m using for creating and stopping the process 1)Creating a process success = ::CreateProcess(temp,cmdstr,0,0,FALSE,CREATE_NEW_CONSOLE,0,0,&startupinfo,&procinfo); where temp and cmdstr are application path and command line argument that i pass 2) terminating process HANDLE hn = ::OpenProcess(PROCESS_ALL_ACCESS,false,id); if(hn != NULL) { ::TerminateProcess(hn,0); } now here OpenProcess API fails and gives error........id is the process id of the process i started using a service......please suggest me a way out of this. thanks kunal s patel
-
Hi all i have a code where i am starting the process from a windows service that i created. Now i want to terminate that process using some other application(MFC stand alone) application. But when ever i try to do that,it gives error 5 which documentation says is "Error Access Denied"......here r the codes that i m using for creating and stopping the process 1)Creating a process success = ::CreateProcess(temp,cmdstr,0,0,FALSE,CREATE_NEW_CONSOLE,0,0,&startupinfo,&procinfo); where temp and cmdstr are application path and command line argument that i pass 2) terminating process HANDLE hn = ::OpenProcess(PROCESS_ALL_ACCESS,false,id); if(hn != NULL) { ::TerminateProcess(hn,0); } now here OpenProcess API fails and gives error........id is the process id of the process i started using a service......please suggest me a way out of this. thanks kunal s patel
The MSDN documentation here suggests that if you are trying to do OpenProcess with all access, you need to enable SeDebugPrivilege privilege. This is because all PROCESS_ALL_ACCESS includes access like reading/writing the target process' address space which is a privilege normally reserved for debuggers. If all you are doing is terminating the process, you should specify the minimum amount of access required to do that.
-
The MSDN documentation here suggests that if you are trying to do OpenProcess with all access, you need to enable SeDebugPrivilege privilege. This is because all PROCESS_ALL_ACCESS includes access like reading/writing the target process' address space which is a privilege normally reserved for debuggers. If all you are doing is terminating the process, you should specify the minimum amount of access required to do that.
Considering wat u said i changed the PROCESS_ALL_ACCESS to PROCESS_TERMINATE and tried it but again it failed so now i guess only option left is setting SeDebugPrivilege....now i really dont have a clue how to do it....please suggest me a way out of it