KillProcess proc lpszExecutable:LPSTR
LOCAL bLoop:BOOL
LOCAL bResult:BOOL
LOCAL pe32:PROCESSENTRY32
LOCAL hProcess:HANDLE
LOCAL hProcesses:HANDLE
mov bLoop,TRUE
mov bResult,FALSE
invoke CreateToolhelp32Snapshot,TH32CS_SNAPPROCESS,0
mov hProcesses,eax ; Did not need 2 copies of your snap shot
mov pe32.dwSize,SIZEOF PROCESSENTRY32
invoke Process32First,hProcesses,ADDR pe32
.IF eax
.WHILE bLoop
invoke CompareString, LOCALE_USER_DEFAULT, NORM_IGNORECASE, addr pe32.szExeFile, -1, lpszExecutable, -1
.IF eax==2
invoke OpenProcess, PROCESS_TERMINATE, FALSE, pe32.th32ProcessID ; With having addr pe32.th32ProcessID you were getting an invalid PID..
.IF eax!=NULL
mov hProcess, eax ; Need to save the process handle to terminate
invoke TerminateProcess, hProcess, 0
invoke CloseHandle, hProcess
mov bResult,TRUE;
.endif
.endif
invoke Process32Next, hProcesses, ADDR pe32
mov bLoop,eax
.endw
invoke CloseHandle,hProcesses
.endif
mov eax,bResult
ret
KillProcess endp
|