AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Thema durchsuchen
Ansicht
Themen-Optionen

Ärger mit Shellexecute

Ein Thema von Delbor · begonnen am 29. Mai 2022 · letzter Beitrag vom 4. Jun 2022
 
Benutzerbild von KodeZwerg
KodeZwerg

Registriert seit: 1. Feb 2018
3.691 Beiträge
 
Delphi 11 Alexandria
 
#9

AW: Ärger mit Shellexecute

  Alt 31. Mai 2022, 19:56
Vielleicht hilft dir mein code schnippsel weiter um ans ziel zu gelangen.
Delphi-Quellcode:
type
  TExec = packed record
    Filename : string;
    PID : DWORD;
    WindowHandle : HWND;
  end;

var
  Exec: TExec;

procedure ResetExec;
begin
  Exec.Filename := '';
  Exec.PID := 0;
  Exec.WindowHandle := 0;
end;

function EnumWindowsProc(Wnd : HWND; ProcessID : Cardinal) : Boolean; stdcall;
var
  PID : Cardinal;
begin
  GetWindowThreadProcessId(Wnd, @PID);
  if ProcessID = PID then
    Exec.WindowHandle := Wnd;
  Result := True;
end;

function ExecFile(const AFilename: string): Boolean;
var
  Executable : string;
  Security : TSecurityAttributes;
  ProcessInfo: TProcessInformation;
  StartupInfo: TStartupInfo;
  dummy : HINST;
begin
  Result := False;
  ResetExec;

  if (not FileExists(AFilename)) then
    Exit;

  SetLength(Executable, MAX_PATH);
  dummy := FindExecutable(PChar(AFilename), nil, PChar(Executable));
  if dummy > 32 then
  begin
    SetLength(Executable, StrLen(PChar(Executable)));
    UniqueString(Executable);

    Security.nLength := SizeOf(TSecurityAttributes);
    Security.lpSecurityDescriptor := nil;
    Security.bInheritHandle := False;

    FillChar(StartupInfo, SizeOf(TStartupInfo), #0);
    StartupInfo.cb := SizeOf(TStartupInfo);
    StartupInfo.dwFlags := STARTF_USESHOWWINDOW or STARTF_FORCEONFEEDBACK;
    StartupInfo.wShowWindow := SW_SHOWNORMAL {SW_HIDE};

    Win32Check(CreateProcess(PChar(Executable), PChar(Format('%s %s', [Executable, AFilename])), @Security, @Security, False, CREATE_NEW_CONSOLE or NORMAL_PRIORITY_CLASS, nil, PChar(ExtractFilePath(Executable)), StartupInfo, ProcessInfo));
    try
      WaitForInputIdle(ProcessInfo.hProcess, INFINITE);
      Exec.Filename := Executable;
      Exec.PID := ProcessInfo.dwProcessId;
      EnumWindows(@EnumWindowsProc, LPARAM(Exec.PID));
    finally
      CloseHandle(ProcessInfo.hProcess);
      CloseHandle(ProcessInfo.hThread);
      Result := True;
    end;
  end;
end;
nach dem aufruf steht in globaler variable Exec.WindowHandle was du brauchst. Ist ein Versuch Wert.
Gruß vom KodeZwerg
  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 22:06 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