Nyt forsoeg:
program shell;
uses
ShellApi, Windows;
function MyGetProcessId(Process: HANDLE ): DWORD; external kernel32 name 'GetProcessId';
function kill(wnd: HWND; prc: LPARAM): BOOL; StdCall;
var
id : LONGWORD;
begin
GetWindowThreadProcessId(wnd, @id);
writeln(prc, ' ', id);
if prc = id then begin
PostMessage(wnd, WM_QUIT, 0, 0);
end;
result := true;
end;
var
sei : TShellExecuteInfo;
begin
//ShellExecute(0, 'open', 'Notepad', nil, nil, SW_SHOWNORMAL);
ZeroMemory(@sei, SizeOf(sei));
sei.cbSize := SizeOf(TShellExecuteInfo);
sei.lpVerb := 'open';;
sei.lpFile := PChar('Notepad');
sei.fMask := SEE_MASK_NOCLOSEPROCESS;
sei.nShow := SW_SHOWNORMAL;
ShellExecuteEx(LPShellExecuteInfoA(@sei)); // LPShellExecuteInfoA cast may not needed or good
Sleep(15000);
//PostMessage(sei.hProcess, WM_QUIT, 0, 0);
EnumWindows(@kill, MyGetProcessId(sei.hProcess));
end.