bueno preferiria mandar comprimido el codigo y no se como hacerlo en este foro asi que mandare partes del codigo que tengo sobre eso espero que te ayude en algo
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include <tlhelp32.h>
#include "stdio.h"
#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button1Click(TObject *Sender)
{
// Find each process and display it.
HANDLE snapshot ;
PROCESSENTRY32 processinfo ;
processinfo.dwSize = sizeof (processinfo) ;
snapshot = CreateToolhelp32Snapshot (TH32CS_SNAPALL , 0) ;
if (snapshot == NULL)
return ;
bool status = Process32First (snapshot, &processinfo) ;
while (status)
{
Edit1->Text = Edit1->Text + processinfo.szExeFile + ",";
status = Process32Next (snapshot, &processinfo) ;
}
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button2Click(TObject *Sender)
{
HANDLE miHandle;
miHandle = FindWindow(NULL, "Warcraft III");
// aqui esta lo que quieres facil muy juacil lo otro es para procesos problematicos
SendMessage(miHandle, WM_CLOSE, 0, 0);
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button3Click(TObject *Sender)
{
DWORD ProcessID;
HANDLE hp;
HANDLE hSnapShot = ::CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS,0);
if(hSnapShot == 0)
return;
PROCESSENTRY32 thePE;
thePE.dwSize = sizeof(PROCESSENTRY32);
bool Status = Process32First(hSnapShot,&thePE);
bool bHaveFlag = false;
while(Status)
{
Status = Process32Next(hSnapShot,&thePE);
if(AnsiString(ExtractFileName(thePE.szExeFile)) == "war3.exe")
{
ShowMessage("encontrado");
ProcessID = thePE.th32ProcessID;
hp=OpenProcess(PROCESS_TERMINATE,FALSE,ProcessID);
if (hp==NULL)
{
DWORD error = GetLastError();
Edit3->Text = error;
}
TerminateProcess(hp,0);
if(!TerminateProcess(OpenProcess(PROCESS_ALL_ACCESS,false,ProcessID),0))
ShowMessage("No terminadao");
break;
}
}
CloseHandle(hSnapShot);
}
//---------------------------------------------------------------------------
bool AddDebugPrivilege(void)
{
//TODO: Add your source code here
HANDLE Token;
TOKEN_PRIVILEGES TokenPrivileges, PreviousState;
DWORD ReturnLength = 0;
if(OpenProcessToken(GetCurrentProcess(), TOKEN_QUERY | TOKEN_ADJUST_PRIVILEGES, &Token))
if(LookupPrivilegeValue(NULL, "SeDebugPrivilege", &TokenPrivileges.Privileges[0].Luid))
{
TokenPrivileges.PrivilegeCount = 1;
TokenPrivileges.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
return (AdjustTokenPrivileges(Token, FALSE, &TokenPrivileges,sizeof (TOKEN_PRIVILEGES), &PreviousState, &ReturnLength));
}
return(FALSE);
}
void __fastcall TForm1::Button4Click(TObject *Sender)
{
bool a;
a = AddDebugPrivilege();
}
//---------------------------------------------------------------------------