Einzelnen Beitrag anzeigen

Benutzerbild von KodeZwerg
KodeZwerg

Registriert seit: 1. Feb 2018
3.685 Beiträge
 
Delphi 11 Alexandria
 
#7

AW: Shellexecute richtig anwenden/übersetzen

  Alt 15. Okt 2018, 17:17
Da in Delphi die Anführungszeichen ja eh anders sind, wäre die richtige Umsetzung dann wohl:
  ShellExecute('RUNDLL32.exe', 'PRINTUI.DLL,PrintUIEntry /k /n "PDFCreator"', '', 'open', 1);
Delphi-Quellcode:
uses ShellApi;

...

function ExecuteShell(const Executable, Commands: String; const ShowConsole: Boolean): Cardinal;
 var
  ProcessInfo: TShellExecuteInfo;
 begin
  Result := Cardinal($FFFFFFFF);
  FillChar(ProcessInfo, SizeOf(TShellExecuteInfo), #0);
  with ProcessInfo do
  begin
   cbSize:= SizeOf( TShellExecuteInfo );
   fMask := SEE_MASK_NOCLOSEPROCESS or SEE_MASK_FLAG_DDEWAIT;
   Wnd := GetActiveWindow();
   lpVerb := 'open';
   lpFile:= PChar(Executable);
   lpParameters := PChar(Commands);
   lpDirectory := PChar(ExtractFilePath(Executable)); // <<-- diese zeile könnte probleme verursachen, eventuell anpassen (!)
   if ShowConsole then nShow := SW_SHOWDEFAULT else nShow := SW_HIDE;
  end;
  if ShellExecuteEx(@ProcessInfo) then
  begin
   if not GetExitCodeProcess(ProcessInfo.hProcess, Result) then Result := Cardinal($FFFFFFFF);
// GetExitCodeProcess(ProcessInfo.hProcess, Result);
   CloseHandle(ProcessInfo.hProcess);
  end
  else
  begin
   Result := GetLastError;
   exit;
  end;
 end;


...

ExecuteShell('RUNDLL32.exe', 'PRINTUI.DLL,PrintUIEntry /k /n "PDFCreator"', True);
Vielleicht klappt das?
Gruß vom KodeZwerg

Geändert von KodeZwerg (15. Okt 2018 um 17:36 Uhr)
  Mit Zitat antworten Zitat