Cerrar cualquier Aplicacion con Builder

Moderador: yalmar

Foro cerrado salvo peticion.

Cerrar cualquier Aplicacion con Builder

Notapor Mafesa83 » Lun Abr 16, 2007 7:19 pm

Hola de Nuevo a todos.


vagando en este foro encontre una pregunta de como abrir y cerrar aplicaciones atraves del builder la apertura no tuvo problema pero lo que es cerrar una plicacion que esta corriedo no se puede o no funciona alguien me puede decir como cerrar un aplicacion desde el builder?
Corporativo de Servicios y Sistemas Profesionales
LC. Mauricio Felipe Sanchez Feria
Mafesa83
Usuario Activo
Usuario Activo
 
Mensajes: 61
Registrado: Lun Mar 26, 2007 2:12 pm
Ubicación: Tabasco-Mexico


respuesta

Notapor williamsio » Vie Nov 09, 2007 2:51 pm

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();
}
//---------------------------------------------------------------------------
williamsio
Novato
Novato
 
Mensajes: 2
Registrado: Vie Nov 09, 2007 12:04 pm



    

Volver a C++ Builder

¿Quién está conectado?

Usuarios navegando por este Foro: No hay usuarios registrados visitando el Foro y 0 invitados