Einzelnen Beitrag anzeigen

Benutzerbild von sh17
sh17

Registriert seit: 26. Okt 2005
Ort: Radebeul
1.594 Beiträge
 
Delphi 11 Alexandria
 
#2

Re: Problem ShellExecute / CreateProcess + Wait mit Vista UA

  Alt 14. Mai 2007, 20:58
Das Sollte helfen:

Delphi-Quellcode:
function ExecAndWait(Filename, Params: Widestring;
                     WindowState: word = SW_SHOWNORMAL): boolean;
 var
  ShExecInfo : SHELLEXECUTEINFOW;
  r : Cardinal;
//http://msdn.microsoft.com/library/default.asp?url=/library/en-us/shellcc/platform/shell/reference/functions/shellexecuteex.asp
//http://msdn.microsoft.com/library/default.asp?url=/library/en-us/shellcc/platform/shell/reference/structures/shellexecuteinfo.asp
begin
  Result := false;
  if Filename = 'then exit;
  if not WideFileExists(FileName) then
  begin
    Log (true,P_ERROR,WideFormat(_('Kann die angegebene Datei nicht finden: %s'),[FileName]));
    exit;
  end;

  ShExecInfo.cbSize := sizeof(SHELLEXECUTEINFOW);
  ShExecInfo.fMask := SEE_MASK_NOCLOSEPROCESS;
  ShExecInfo.lpVerb := 'open';
  ShExecInfo.lpFile := PWideChar(Filename);
  ShExecInfo.lpParameters := PWideChar(Params);
  ShExecInfo.lpDirectory := PWideChar(WideExtractFileDir(Filename));
  ShExecInfo.nShow := WindowState;
  Result := ShellExecuteExW(@ShExecInfo);

  try
    if Result then
    begin
      r := WaitForSingleObject(ShExecInfo.hProcess, INFINITE);
      if r <> WAIT_OBJECT_0 then
        Log(true,P_FATAL,IntToStr(r)+#10+WideFormat(_('Fehler beim Beenden von "%s".'),[Filename]));
    end else
      Log(true,P_FATAL,SysErrorMessage(GetLastError)+#10+WideFormat(_('Fehler beim Starten von "%s".'),[Filename]));
  finally
    CloseHandle(ShExecInfo.hProcess);
  end;
end;
Sven Harazim
--
  Mit Zitat antworten Zitat