有两种方法:<br>procedure TForm1.CloseClient;<br>var<br> hCurrentWindow:HWnd;S:string;<br> szText:array[0..254] of char;<br> pCname:array[0..100] of char;<br>begin<br> hCurrentWindow := GetWindow(Handle, GW_HWNDFIRST);<br> while hCurrentWindow <> 0 do<br> begin<br> if GetWindowText(hCurrentWindow, @szText, 255) > 0 then<br> begin<br> S:=StrPas(@szText);<br> if (pos('监控',s)>0) and (pos('AGENT',uppercase(s))=0) then<br> begin<br> if isWindow(hCurrentWindow) then<br> begin<br> GetClassName(hCurrentWindow,pCname,100);<br> if Not (Pos('CABINETWCLASS',UpperCase(StrPas(pCname)))>0) then //检查是否为Forlder;<br> begin<br> SendMessage(hCurrentWindow,WM_CLOSE,0,0);<br> Application.ProcessMessages;<br> isClientRuned:=True;<br> end; <br> end;<br> end;<br> end;<br> hCurrentWindow := GetWindow(hCurrentWindow, GW_HWNDNEXT);<br> end;<br>end;<br>{var user tlhelp32;<br> lppe:tprocessentry32;sshandle:thandle;<br> hh:hwnd;found:boolean;<br>begin<br>sshandle:=createtoolhelp32snapshot(TH32CS_SNAPALL,0);<br>found:=process32first(sshandle,lppe);<br> while found do<br> begin<br> //进行你的处理其中lppe.szExefile就是程序名。<br> if uppercase(extractfilename(lppe.szExeFile))='CLIENT.EXE' then<br> begin<br> hh:=OpenProcess(PROCESS_ALL_ACCESS,true,lppe.th32ProcessID);<br> TerminateProcess(hh,0);<br> Application.ProcessMessages;<br> isClientRuned:=True;<br> CloseHandle(sshandle);<br> Exit;<br> end;<br> found:=process32next(sshandle,lppe);<br> end;<br> CloseHandle(sshandle);<br>end; }<br>