![]() |
Programm starten und warten bis es beendet wird
Hi Leute ich habe mehrere Fragen, es eilt ganz dolle, wäre echt geil wenn ihr helfen könntet!
1. Will ich aus einem Delphi Programmheraus ein Winupdate startet dieses wird mit Start/Ausführen "NDP1.1sp1-KB867460-X86.exe /q:" aufgerufen und muss auch so aus dem Delphi Prog gestartet werden 2. Will ich in Delphi auf die ausführung dieses Programmes warten 3. Ist es Möglich den Programmaufruf "NDP1.1sp1-KB867460-X86.exe /q:" als Parameter zu übergeben ? obwohl dort Leerzeichenvorhanden sind? Vielen Dank für eure Hilfe ! |
Re: Programm starten und warten bis es beendet wird
Schau mal
![]() |
Re: Programm starten und warten bis es beendet wird
thx, werds gleich mal proggen
hast du auch eine idee zu der parameterübergabe ? |
Re: Programm starten und warten bis es beendet wird
Zitat:
|
Re: Programm starten und warten bis es beendet wird
jo klappt alles soweit nur habe ich ein problem
so lange das programm läuft (er also auf die beendung des programmes wartet) hängt mein hauptprogramm gibt es irgendne möglichkeit, da nen application.processmessages einzubauen, damit ich mein hauptprogramm weiterbenutzen kann? |
Re: Programm starten und warten bis es beendet wird
Dann musst du das Starten des Programms am besten in einen separaten Thread verpacken, dann bleibt eine eigentliche Applikation "bedienbar".
|
Re: Programm starten und warten bis es beendet wird
Hallo,
ich benutze für solche Sachen immer diese Funktion:
Delphi-Quellcode:
Vielleicht kannst Du sie ja nach Deinen Anforderungen umbauen.
{ WindowState is one of the SW_xxx constants.
Look up ShowWindow in the API help for a list.} function ExecAndWait(const Filename, Params: string; WindowState: word): boolean; {$IFDEF WIN32} var SUInfo: TStartupInfo; ProcInfo: TProcessInformation; CmdLine: string; begin { Enclose filename in quotes to take care of long filenames with spaces. } CmdLine := '"' + Filename + '" ' + Params; FillChar(SUInfo, SizeOf(SUInfo), #0); with SUInfo do begin cb := SizeOf(SUInfo); dwFlags := STARTF_USESHOWWINDOW; wShowWindow := WindowState; end; try Result := CreateProcess(NIL, PChar(CmdLine), NIL, NIL, FALSE, CREATE_NEW_CONSOLE or NORMAL_PRIORITY_CLASS, NIL, PChar(ExtractFilePath(Filename)), SUInfo, ProcInfo); except on E: Exception do begin Result:=false; end; end; { Wait for it to finish. } if Result then WaitForSingleObject(ProcInfo.hProcess, INFINITE); {$ELSE} var InstanceID : THandle; Buff: array[0..255] of char; begin StrPCopy(Buff, Filename + ' ' + Params); InstanceID := WinExec(Buff, WindowState); if InstanceID < 32 then { a value less than 32 indicates an Exec error } Result := FALSE else begin Result := TRUE; repeat Application.ProcessMessages; until Application.Terminated or (GetModuleUsage(InstanceID) = 0); end; {$ENDIF} end; Grüße Klaus |
Re: Programm starten und warten bis es beendet wird
hmm was ist das denn fürn komisch quellcode ?
|
Re: Programm starten und warten bis es beendet wird
@meisteralex: Ich hab den Quelltext von Klausi01 mal noch etwas umgebaut (dann verstehst du Ihn wahrscheinlich besser) und auch schon ein "Application.Processmessages" mit reingemacht. Damit sollte es funktionieren!
Delphi-Quellcode:
{ WindowState is one of the SW_xxx constants.
Look up ShowWindow in the API help for a list.} function ExecAndWait(const Filename, Params: string; WindowState: word): boolean; var SUInfo: TStartupInfo; ProcInfo: TProcessInformation; CmdLine: string; begin { Enclose filename in quotes to take care of long filenames with spaces. } CmdLine := '"' + Filename + '" ' + Params; FillChar(SUInfo, SizeOf(SUInfo), #0); with SUInfo do begin cb := SizeOf(SUInfo); dwFlags := STARTF_USESHOWWINDOW; wShowWindow := WindowState; end; try Result := CreateProcess(NIL, PChar(CmdLine), NIL, NIL, FALSE, CREATE_NEW_CONSOLE or NORMAL_PRIORITY_CLASS, NIL, PChar(ExtractFilePath(Filename)), SUInfo, ProcInfo); except on E: Exception do begin Result:=false; end; end; { Wait for it to finish. } if Result then begin Application.Processmessages; // <-- diese Zeile hab ich eingefügt!!! WaitForSingleObject(ProcInfo.hProcess, INFINITE); end; end; |
Re: Programm starten und warten bis es beendet wird
friert trotzdem ein
das einfrieren liegt ja an WaitForSingleObject und ein application.processmessages davor bringt ja dann auch net viel |
Alle Zeitangaben in WEZ +1. Es ist jetzt 08:21 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