知道程序名也可关闭它。<br>下面两段代码希望对你有用:<br><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> file://进行你的处理其中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>/////////////////////////////////////////////////////////////////<br>uses tlhelp32;<br>假设要终止的程序的文件名为:project2.exe,那么例程如下:<br>var<br>lppe:tprocessentry32;<br>sshandle:thandle;<br>hh:hwnd;<br>found:boolean;<br>begin<br>sshandle:=createtoolhelp32snapshot(TH32CS_SNAPALL,0);<br>found:=process32first(sshandle,lppe);<br>while found do<br>begin<br> file://进行你的处理其中lppe.szExefile就是程序名。<br> if uppercase(extractfilename(lppe.szExeFile))='PROJECT2.EXE' then<br> begin<br> hh:=OpenProcess(PROCESS_ALL_ACCESS,true,lppe.th32ProcessID);<br> TerminateProcess(hh,0);<br> end;<br> found:=process32next(sshandle,lppe);<br>end;<br>end;<br>