Einzelnen Beitrag anzeigen

QuickAndDirty

Registriert seit: 13. Jan 2004
Ort: Hamm(Westf)
1.892 Beiträge
 
Delphi 12 Athens
 
#5

AW: Too stupid to execute and wait

  Alt 9. Aug 2011, 10:51
Funktioniert wunderbar:
Delphi-Quellcode:
uses
  ShellAPI;

procedure ExecAndWait(Filename, Params: Widestring; WindowState: word = SW_SHOWNORMAL);
var
  ShExecInfo: SHELLEXECUTEINFOW;
const
  SEE_MASK_NOASYNC= $100;
begin
  ZeroMemory(@ShExecInfo, SizeOf(ShExecInfo));
  ShExecInfo.Wnd := GetForegroundWindow;
  ShExecInfo.cbSize := sizeof(SHELLEXECUTEINFOW);
  ShExecInfo.fMask := SEE_MASK_NOCLOSEPROCESS or SEE_MASK_NOASYNC;
  ShExecInfo.lpVerb := 'open';
  ShExecInfo.lpFile := PWideChar(Filename);
  ShExecInfo.lpParameters := PWideChar(Params);
  ShExecInfo.lpDirectory := PWideChar(WideString(ExtractFileDir(Filename)));
  ShExecInfo.nShow := WindowState;
  if ShellExecuteExW(@ShExecInfo) then
  begin
    WaitForSingleObject(ShExecInfo.hProcess, INFINITE);
    CloseHandle(ShExecInfo.hProcess);
  end
  else
    RaiseLastOSError;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  try
    ExecAndWait('C:\Windows\Notepad.exe', '');
  except
    on E: Exception do
      ShowMessage(E.Message);
  end;
  ShowMessage('Fertig');
end;
Ja mit notepad funktioniert es wunderbar,
mit isql.exe geht es und mit gsec.exe geht es auch

Aber mit meiner setup.exe ist nach dem Splashscreen Schluss.
Warum?
Andreas
Monads? Wtf are Monads?
  Mit Zitat antworten Zitat