Habe das jetzt heilwegs gelöst:
Habe zum starten und stoppen ein anderes (Kommandozeilen-)Programm geschrieben:
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66:
| program EchoT; {$APPTYPE CONSOLE}
uses SysUtils, Forms, Windows, Tlhelp32, ShellApi;
procedure Wait(time: double); var Start: Integer; begin Start:=GetTickCount; while GetTickCount-Start <= time do application.ProcessMessages; end;
function KillTask(ExeFileName: string): integer; const PROCESS_TERMINATE=$0001; var ContinueLoop: BOOL; FSnapshotHandle: THandle; FProcessEntry32: TProcessEntry32; begin result := 0;
FSnapshotHandle := CreateToolhelp32Snapshot (TH32CS_SNAPPROCESS, 0); FProcessEntry32.dwSize := Sizeof(FProcessEntry32); ContinueLoop := Process32First(FSnapshotHandle, FProcessEntry32);
while integer(ContinueLoop) <> 0 do begin if ((UpperCase(ExtractFileName( FProcessEntry32.szExeFile)) = UpperCase(ExeFileName)) or (UpperCase(FProcessEntry32.szExeFile) = UpperCase(ExeFileName))) then
Result := Integer(TerminateProcess(OpenProcess( PROCESS_TERMINATE, BOOL(0), FProcessEntry32.th32ProcessID), 0));
ContinueLoop := Process32Next(FSnapshotHandle, FProcessEntry32); end;
CloseHandle(FSnapshotHandle); end; begin if ParamStr(1)='/remctrl' then if ParamStr(2)='/ctrl-disconnect' then begin KillTask('PortIO.exe'); WriteLN('habe beendet: PortIO.exe'); end; if ParamStr(1)='/remctrl' then if ParamStr(2)='/ctrl-connect' then begin ShellExecute(0,Nil, PChar('D:\Public\HTTP\webcam\PortIO\PortIO.exe'), Nil, Nil, SW_NORMAL); WriteLN('habe gestartet: PortIO.exe'); end; if ParamStr(1)='' then begin WriteLN('keine Aufgabe uebergeben'); wait(10000); end; end. |
Das funktioniert soweit auch.
Auch kann ich an ein laufendes Programm übergebene Daten lesen, wenn es per Doppelklick oder Kommandozeile gestartet wurde.
Das Problem ist noch, dass wenn ich mit dem Hilfsprogramm starte, keine Oberfläche vorhanden ist, und das auch keine Befehle abgearbeitet werden.
Liegt das an Shellexecute?
Habt ihr wieder so ne gute Idee?
--> Habe mittlerweile auch rausbekommen, dass die Anwendung zwar gestartet wird, aber weder ins Form.Creat noch Form.Close geht, also muss irgendwo ja ein Absturzfehler sein, richtig?
Habe gerade was von createprocess gelesen, hilft mir das denn?