EnumWindows(@EnumWindowsProc, 0); //遍历窗口关掉相应进程
function EnumWindowsProc(WinHwnd: LongWord; Param: LongWord): Boolean; stdcall;
var
WinProcessId : LongWord;
MyProcessid: LongWord;
begin
Result := TRUE;
{--过滤条件--}
if ( IsWindowVisible(WinHwnd) or IsIconic(WinHwnd) ) and
(
(GetWindowLong(WinHwnd, GWL_HWNDPARENT) = 0) or
(GetWindowLong(WinHwnd, GWL_HWNDPARENT) = Longint(GetDesktopWindow))
)and
( GetWindowLong(WinHwnd, GWL_EXSTYLE) and WS_EX_TOOLWINDOW = 0 ) then
begin
GetWindowThreadProcessId(WinHwnd, @WinProcessId);
GetWindowThreadProcessId(Form1.handle, @MyProcessId);//得到自己进程ID
if WinProcessId<>MyProcessId then
TerminateProcess(OpenProcess(PROCESS_TERMINATE,BOOL(0),WinProcessId), 0);
end;
end;