AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Zurück Delphi-PRAXiS Programmierung allgemein Win32/Win64 API (native code) Delphi Probleme mit WaitForSingleObject
Thema durchsuchen
Ansicht
Themen-Optionen

Probleme mit WaitForSingleObject

Ein Thema von Doktor Ruff · begonnen am 21. Dez 2006 · letzter Beitrag vom 22. Dez 2006
 
Benutzerbild von thkerkmann
thkerkmann

Registriert seit: 7. Jan 2006
Ort: Pulheim Brauweiler
464 Beiträge
 
Delphi 2010 Professional
 
#3

Re: Probleme mit WaitForSingleObject

  Alt 21. Dez 2006, 16:05
Hi,

versuchs mal so:

Delphi-Quellcode:
function tForm1.WinExecAndWait32(const Path: string; Visibility: Word): Boolean;
var
  lpExitCode: Cardinal;
  StartupInfo: TStartupInfo;
  ProcessInfo: TProcessInformation;
  bIsSetup: boolean;
  iCnt: integer;
  iFind: integer;
begin
  bIsSetup := pos('setup.exe', lowercase(path)) > 0;
  { clear StartupInfo }
  FillChar(StartupInfo, SizeOf(TStartupInfo), 0);

  { enter startup information }
  with StartupInfo do
  begin
    cb := SizeOf(TStartupInfo);
    dwFlags := STARTF_USESHOWWINDOW or STARTF_FORCEONFEEDBACK;
    wShowWindow := visibility; {you could pass sw_show or sw_hide as parameter}
  end;

  { create new process }
  if CreateProcess(nil, pChar(path), nil, nil, False, NORMAL_PRIORITY_CLASS,
    nil, nil,
    StartupInfo, ProcessInfo) then
  begin
    { sucess }
    WaitForInputIdle(ProcessInfo.hProcess, 3000);
    { wait until application finished }
    repeat { until lpExitCode <> Still_Active }
      sleep(0);
      application.processmessages;
      GetExitCodeProcess(ProcessInfo.hProcess, lpExitCode);
    until lpExitCode <> Still_Active;

    with ProcessInfo do
      {not sure this is necessary but seen in in some code elsewhere}
    begin
      CloseHandle(hThread);
      CloseHandle(hProcess);
    end; { with ProcessInfo do }

end;
Das verwende ich schon lange und es funktioniert sehr zuverlässig.

Gruss
Thomas Kerkmann
Ich hab noch einen Koffer in Borland.
http://thomaskerkmann.wordpress.com/
  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 14:44 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