tags:

views:

472

answers:

3

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 32bit platform but on 64 bit platform OpenProcess returns Access_denied for some processes(the same processes on 32 bit can be computed fine). All processes I trying to open are 32bit.

What can be a problem?

A: 

Could it be that the user you are logged in on the 64-bit platform does not have the rights to terminate those processes ? e.g. on Vista, UAC is active, you are an admin but not running elevated and trying to close system processes.

RaphaelSP
No, I have all rights I need to terminate the process.
Oh, and it seems that OpenProcess() would have failed in such a case.
RaphaelSP
A: 

This might be really out there, but are you executing the code from a network drive? I've seen .NET applications fail to do very basic things when run from a network drive.

If you are, try moving the executable to a local disk and see if that helps.

Yes, I know this is a very weird suggestion, I just figure if that's the problem it might help :-)

scraimer
+1  A: 

Is your application a 64-bit process or a 32-bit process? You can't 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 should be able to open other 64-bit processes and 32-bit processes.

If your app is 32-bit, it is probably a permissions problem. Try running it as Administrator and see if that resolves the problem.

Andrew Sandoval