OpenProcess returns access_denied on 64 bit platform
I have a function:
HANDLE snapshot=CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
...
result=Process32First(snapshot,&pe);
while(result) {
if(!_stricmp(process_name,pe.szExeFile)) {
processes.push_back(pe.th32ProcessID);
}
result=Process32Next(snapshot,&pe);
}
for(dword_vector::iterator i=processes.begin(); i!=processes.end(); ++i){
HANDLE hProcess=OpenProcess(PROCESS_TERMINATE, FALSE, *i);
if(hProcess) {
TerminateProcess(hProcess, 0);
CloseHandle(hProcess);
}
}
It works fine on 32-bit platform, but on 64-bit platform OpenProcess returns Access_denied for some processes (the same processes on a 32-bit basis can be computed fine). All processes I try to open are 32bit.
What could be the problem?
It may be valid, but are you executing the code from the network disk ? I've seen .NET applications fail to do very simple things when launched from a network drive.
If so, try moving the executable to your local drive and see if that helps.
Yes, I know this is a very strange suggestion, I just think this problem might help :-)
a source to share
Is your application a 64-bit process or a 32-bit process? You cannot open a 64 bit process from a 32 bit process.
Use Task Manager to make sure your application is 64-bit. If not, fix and compile it as 64-bit and you can open other 64-bit processes and 32-bit processes.
If your application is 32-bit it is probably a permissions issue. Try running it as administrator and see if that fixes the problem.
a source to share