lpdwProcessId param returns the Process ID that you need to use.
The one you was using is a Thread ID.
Extern "win32" Function EnumWindows(Callbackptr:Byte Ptr,lParam) Function GetWindowText(hWnd,lpString:Byte Ptr,nMaxCount) = "GetWindowTextA@12" Function OpenProcess% (access, handleinherit, processid) Function TerminateProcess% (processhandle, exitcode) Function CloseHandle% (Objects) Function GetWindowThreadProcessId(hWnd:Int,ID:Byte Ptr) = "GetWindowThreadProcessId@8" Function GetClassName(hWnd:Int,clString:Byte Ptr,nMaxCount:Int) = "GetClassNameA@12" End Extern Const PROCESS_TERMINATE = $1 Const PROCESS_CREATE_THREAD = $2 Const PROCESS_VM_OPERATION = $8 Const PROCESS_VM_READ = $10 Const PROCESS_VM_WRITE = $20 Const PROCESS_DUP_HANDLE = $40 Const PROCESS_CREATE_PROCESS = $80 Const PROCESS_SET_QUOTA = $100 Const PROCESS_SET_INFORMATION = $200 Const PROCESS_QUERY_INFORMATION = $400 Const SYNCHRONIZE = 1048576 Const STANDARD_RIGHTS_REQUIRED = 983040 Const PROCESS_ALL_ACCESS = 983040 Global CharBuffer:Byte[255] Function EnumWindowsProc(hwnd,lParam) Local TID:Int Local PID:Int GetWindowText(hwnd,CharBuffer,255) TID=GetWindowThreadProcessid(hwnd,Varptr PID) If String.FromCString(CharBuffer)<>"" Then ' Skip empty process names (threads?) Print "PID: "+PID+"~t hWnd: "+hwnd+" ~t"+String.FromCString(CharBuffer) End If If Instr(String.FromCString(CharBuffer),"Calculator") Then Notify PID DebugLog KillProcess(PID) ' End If 'Return True if you want to fetch the next window, return False to tell EnumWindows to stop. Return True End Function EnumWindows(EnumWindowsProc,0) Function KillProcess (pid) phandle = OpenProcess (PROCESS_TERMINATE, False, pid) If phandle <> 0 If TerminateProcess (phandle, 1) result = 1 EndIf CloseHandle (phandle) EndIf Return result End Function
The one you was using is a Thread ID.