Llevo peleandome varios dias con esta función. No me compilaba, y gracias a la ayuda de Eternal Idol, he podido hacer almenos que compile.
int KillProcess(LPCTSTR lpfilename){
//WIN32_FIND_DATA Win32FindData; <-- No se usa ¿?
HANDLE handle;
DWORD exitcode;
PROCESSENTRY32 pe32;
handle = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
if(handle == INVALID_HANDLE_VALUE) return ERROR_LLISTA;
pe32.dwSize = sizeof(PROCESSENTRY32);
if(!Process32First(handle, &pe32)) {
CloseHandle(handle);
return ERROR_PROCES;
}
//TROZO CAMBIADO-------------------------------------------------------------------------------------------------------
int tam = wcslen(lpfilename);
wchar_t *lpfilename2 = new wchar_t[tam + 1];
wcscpy(lpfilename2, lpfilename);
delete[] lpfilename2;
//-------------------------------------------------------------------------------------------------------------------------
for(int i = 0; pe32.szExeFile[i] != '\0'; i++) pe32.szExeFile[i] = toupper(pe32.szExeFile[i]);
for(int i = 0; lpfilename2[i] != '\0'; i++) lpfilename2[i] = toupper(lpfilename2[i]);
while(wcscmp(pe32.szExeFile,lpfilename2)) {
if(!Process32Next(handle, &pe32)) {
CloseHandle(handle);
return ERROR_PROCES;
}
for(i = 0; pe32.szExeFile[i] != '\0'; i++) pe32.szExeFile[i] = toupper(pe32.szExeFile[i]);
}
handle = OpenProcess(PROCESS_ALL_ACCESS, FALSE, pe32.th32ProcessID);
if(handle == NULL) {
CloseHandle(handle);
return ERROR_PROCES;
}
else {
GetExitCodeProcess(handle, &exitcode);
TerminateProcess(handle, exitcode);
CloseHandle(handle);
return 0;
}
}La pruebo con calc.exe per me tira un error de proceso. Tengo varia preguntas. Primero, hay una variable que no se usa. Luego PROCESSENTRY32 pe32; que es? y la ultima, vara obtener el exitcode de un proceso, primero hay que abrir el proceso??