Einzelnen Beitrag anzeigen

Killi138

Registriert seit: 18. Okt 2003
Ort: Nellmersbach/Stuttgart
23 Beiträge
 
Delphi 6 Professional
 
#7

Re: TService - Hilfe! Tut sich nix....

  Alt 21. Nov 2003, 09:37
Die Antwort klang schon sehr vielversprechend, aber klappt auch nicht - hier mal der Code:


Code:
procedure ServiceController(CtrlCode: DWord); stdcall;
begin
  Service1.Controller(CtrlCode);
end;

function TService1.GetServiceController: TServiceController;
begin
  Result := ServiceController;
end;

procedure TService1.ServiceStart(Sender: TService; var Started: Boolean);
var
  ProcID: PCardinal;
begin
MessageBox(0, 'Der Service started', 'Info',
    MB_OK + MB_TOPMOST + MB_SERVICE_NOTIFICATION);
   
    RunProcess('C:\Test.exe', SW_MINIMIZE, TRUE, ProcID);
end;

function TService1.RunProcess(FileName: string; ShowCmd: DWORD; wait: Boolean; ProcID: PCardinal): Longword;
var
  StartupInfo: TStartupInfo;
  ProcessInfo: TProcessInformation;
begin
  FillChar(StartupInfo, SizeOf(StartupInfo), #0);
  StartupInfo.cb         := SizeOf(StartupInfo);
  StartupInfo.dwFlags    := STARTF_USESHOWWINDOW or STARTF_FORCEONFEEDBACK;
  StartupInfo.wShowWindow := ShowCmd;
  if not CreateProcess(nil,
    @Filename[1],
    nil,
    nil,
    False,
    CREATE_NEW_CONSOLE or
    NORMAL_PRIORITY_CLASS,
    nil,
    nil,
    StartupInfo,
    ProcessInfo)
    then
      Result := WAIT_FAILED
  else
  begin
    if wait = FALSE then
    begin
      if ProcID <> nil then ProcID^ := ProcessInfo.dwProcessId;
      exit;
    end;
    WaitForSingleObject(ProcessInfo.hProcess, INFINITE);
    GetExitCodeProcess(ProcessInfo.hProcess, Result);
  end;
  if ProcessInfo.hProcess <> 0 then
    CloseHandle(ProcessInfo.hProcess);
  if ProcessInfo.hThread <> 0 then
    CloseHandle(ProcessInfo.hThread);
end;
Muss ich sonst noch was beachten? Vielleicht hab ich ja beim Einrichten was vergessen....hab sowas noch nie gemacht (Services)
  Mit Zitat antworten Zitat