AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Zurück Delphi-PRAXiS Programmierung allgemein GUI-Design mit VCL / FireMonkey / Common Controls Delphi Problem ShellExecute / CreateProcess + Wait mit Vista UAC
Thema durchsuchen
Ansicht
Themen-Optionen

Problem ShellExecute / CreateProcess + Wait mit Vista UAC

Ein Thema von Assertor · begonnen am 14. Mai 2007 · letzter Beitrag vom 9. Sep 2011
 
Assertor

Registriert seit: 4. Feb 2006
Ort: Hamburg
1.296 Beiträge
 
Turbo C++
 
#4

Re: Problem ShellExecute / CreateProcess + Wait mit Vista UA

  Alt 14. Mai 2007, 21:54
So, die Herren

Vielleicht kann jemand (Sven?) noch mal einen kurzen Blick über den Code werfen. Tests unter Win98 (in VM), Vista und XP laufen soweit. Mit und ohne UAC und der richtigen Einblendung (siehe anderer Thread).

Delphi-Quellcode:
function ExecAndWait(Filename, Params: Widestring;
                     WindowState: word = SW_SHOWNORMAL): boolean;
var
  ShExecInfoW: SHELLEXECUTEINFOW;
  ShExecInfoA: SHELLEXECUTEINFOA;
  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;

  if Win32IsUnicode then
  begin
    ShExecInfoW.Wnd := GetForegroundWindow;
    ShExecInfoW.cbSize := sizeof(SHELLEXECUTEINFOW);
    ShExecInfoW.fMask := SEE_MASK_NOCLOSEPROCESS;
    ShExecInfoW.lpVerb := 'open';
    ShExecInfoW.lpFile := PWideChar(Filename);
    ShExecInfoW.lpParameters := PWideChar(Params);
    ShExecInfoW.lpDirectory := PWideChar(WideExtractFileDir(Filename));
    ShExecInfoW.nShow := WindowState;
    Result := ShellExecuteExW(@ShExecInfoW);
  end
  else
  begin
    ShExecInfoA.Wnd := GetForegroundWindow;
    ShExecInfoA.cbSize := sizeof(SHELLEXECUTEINFOA);
    ShExecInfoA.fMask := SEE_MASK_NOCLOSEPROCESS;
    ShExecInfoA.lpVerb := 'open';
    ShExecInfoA.lpFile := PChar(AnsiString(Filename));
    ShExecInfoA.lpParameters := PChar(AnsiString(Params));
    ShExecInfoA.lpDirectory := PChar(AnsiString(WideExtractFileDir(Filename)));
    ShExecInfoA.nShow := WindowState;
    Result := ShellExecuteExA(@ShExecInfoA);
  end;
  try
    if Result then
    begin
      if Win32IsUnicode then
        r := WaitForSingleObject(ShExecInfoW.hProcess, INFINITE)
      else
        r := WaitForSingleObject(ShExecInfoA.hProcess, INFINITE);
    end;
  finally
    if Win32IsUnicode then
      CloseHandle(ShExecInfoW.hProcess)
    else
      CloseHandle(ShExecInfoA.hProcess);
  end;
end;
Die Logaufrufe von Sven hab ich entfernt bzw. auskommentiert. Die Function Win32IsUnicode ist lediglich ein globaler
(Win32Platform = VER_PLATFORM_WIN32_NT) Danke für Eure Hilfe!

Gruß winkel79
Frederik
  Mit Zitat antworten Zitat
 


Forumregeln

Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are an
Pingbacks are an
Refbacks are aus

Gehe zu:

Impressum · AGB · Datenschutz · Nach oben
Alle Zeitangaben in WEZ +1. Es ist jetzt 08:33 Uhr.
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz