Reputation: 3
I'm trying to make a command which will close all processes, but it will not work for me.
#include "StdAfx.h"
int _tmain(int argc, _TCHAR* argv[])
{
// Get the list of process identifiers.
DWORD ExitCode;
DWORD aProcesses[1024], cbNeeded, cProcesses;
unsigned int i;
if (!EnumProcesses( aProcesses, sizeof(aProcesses), &cbNeeded ) )
{
return 1;
}
// Calculate how many process identifiers were returned.
cProcesses = cbNeeded / sizeof(DWORD);
// exit each process.
for ( i = 0; i < cProcesses; i++ )
{
std::cout<<"end";
if( aProcesses[i] != 0 )
{
GetExitCodeProcess(OpenProcess(PROCESS_ALL_ACCESS,false,aProcesses[i]),&ExitCode);
ExitProcess(ExitCode);
}
}
}
In addition, I get those errors:
> 'check2.exe': Loaded 'C:\Users\Barak Shriky\Documents\Visual Studio 2010\Projects\check2\Debug\check2.exe', Symbols loaded.
'check2.exe': Loaded 'C:\Windows\SysWOW64\ntdll.dll', Symbols loaded (source information stripped).
'check2.exe': Loaded 'C:\Windows\SysWOW64\kernel32.dll', Symbols loaded (source information stripped).
'check2.exe': Loaded 'C:\Windows\SysWOW64\KernelBase.dll', Symbols loaded (source information stripped).
'check2.exe': Loaded 'C:\Windows\SysWOW64\msvcp100d.dll', Symbols loaded (source information stripped).
'check2.exe': Loaded 'C:\Windows\SysWOW64\msvcr100d.dll', Symbols loaded (source information stripped).
'check2.exe': Loaded 'C:\Windows\SysWOW64\psapi.dll', Symbols loaded (source information stripped).
The program '[3292] check2.exe: Native' has exited with code -858993460 (0xcccccccc).
Can someone please help me with this issue?
Upvotes: 0
Views: 317
Reputation: 8469
see the code below where I used terminate process...
// exit each process.
for ( i = 0; i < cProcesses; i++ )
{
std::cout<<"end";
if( aProcesses[i] != 0)
{
GetExitCodeProcess(OpenProcess(PROCESS_ALL_ACCESS,false,aProcesses[i]),&ExitCode);
TerminateProcess(aProcesses[i], ExitCode);
}
}
}
Upvotes: 0
Reputation: 129374
Looks to me like it's working just fine - you just haven't got symbols installed for some system DLL's, which is normal.
Of course, you would get a more meaningful message of why the process exited if you actually set ExitCode
to something - say ExitCode = 0xDeadBeef;
- and then you would see that it was YOUR process that killed itself.
Doing this seems like a very bad thing to do (assuming it is "successful" in closing the process in the first place), since there are certainly plenty of processes in Windows that when stopped causes the rest of the system to not work very well. Such as the page-in/out process, for example, which is also used to load/unload executables. Being SLIGHTLY more selective in which processes you kill will probably be useful.
Upvotes: 0
Reputation: 38825
1) You are not getting any errors
2) ExitProcess is ending your process. Please read the documentation.
Upvotes: 4