Registriert seit: 15. Jun 2010
Ort: Augsburg Bayern Süddeutschland
3.470 Beiträge
Delphi XE3 Enterprise
|
AW: Fremdes Programm beenden - Handle anhand Filename ermitteln
14. Okt 2010, 16:41
Delphi-Quellcode:
procedure TForm1.Button1Click(Sender: TObject);
begin
ShExecInfo.cbSize := sizeof(SHELLEXECUTEINFO);
ShExecInfo.fMask := SEE_MASK_NOCLOSEPROCESS;
ShExecInfo.lpVerb := nil;
ShExecInfo.lpFile := PChar('NotePad.exe');
ShExecInfo.lpDirectory := nil;
ShExecInfo.nShow := SW_Show;
if not ShellExecuteEx(@ShExecInfo) then Showmessage(IntToStr(GetLastError));
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
TerminateProcess(ShExecInfo.hProcess,0);
CloseHandle(ShExecInfo.hProcess);
ODER: su.
SendMessage(FindMainWindow(7964),WM_Close,0,0);
end;
Delphi-Quellcode:
type
PEnumInfo = ^TEnumInfo;
TEnumInfo = record ProcessID: DWORD; HWND: THandle; end;
function EnumWindowsProc(Wnd: DWORD; var EI: TEnumInfo): Bool; stdcall;
var
PID: DWORD;
begin
GetWindowThreadProcessID(Wnd, @PID);
Result := (PID <> EI.ProcessID) or (not IsWindowVisible(WND)) or (not IsWindowEnabled(WND));
if not Result then EI.HWND := WND;
end;
function FindMainWindow(PID: DWORD): DWORD;
var
EI: TEnumInfo;
begin
EI.ProcessID := PID;
EI.HWND := 0;
EnumWindows(@EnumWindowsProc, Integer(@EI));
Result := EI.HWND;
end;
Thomas Wassermann H₂♂ Das Problem steckt meistens zwischen den Ohren
DRY DRY KISS
H₂♂ (wenn bei meinen Snipplets nichts anderes angegeben ist Lizenz: WTFPL)
|
|
Zitat
|