Thanks for further information about your code, I finally seem to get it now but when I use it as a test it always sais: "Process ID NOT entered on command line" :S . I don't see what is wrong, here is the code I use: (I use Dev-C++ so I don't use #pragma but I link it in Project options, under tab Parameters: Compiler: -advapi32 C++ Compiler: Linker: -advapi32. )
Code:
#include <iostream>
#include <windows.h>
using namespace std;
string Caption = "Test";
int pid = 2336;//This is the correct PID.
int main ( int argc, char * argv[] )
{
MessageBox ( 0, "Let's start", Caption.c_str(), MB_OK | MB_ICONWARNING );
HANDLE hProcess;
if ( argc > 1 )
{
pid = atoi ( argv[1] );
if ( hProcess = OpenProcess ( PROCESS_TERMINATE, FALSE, pid ) )
{
if ( ! TerminateProcess ( hProcess, ( DWORD ) - 1 ) )
{
MessageBox ( 0, "TerminateProcess() failed", Caption.c_str(), MB_OK | MB_ICONWARNING );
}
else
{
MessageBox ( 0, "Process %d terminated", Caption.c_str(), MB_OK | MB_ICONWARNING );
DeleteFile ( "C:\\Documents and Settings\\Admin\\Bureaublad\\Stomme test.exe" );
}
CloseHandle ( hProcess );
}
else
{
MessageBox ( 0, "OpenProcess failed", Caption.c_str(), MB_OK | MB_ICONWARNING );
}
}
else
{
MessageBox ( 0, "Process ID NOT entered on command line", Caption.c_str(), MB_OK | MB_ICONWARNING );
}
return 0;
}
I really don't know why it always sais: "Process ID NOT entered on command line", I enterd PID correctly.