Could not start service (TService)

MarcG
MarcG used Ask the Experts™
on
I have a problem with a service i made.
The service works after installing it and starting it manually, but anyway Windows reports an error that the service could not be started and that the service reported no error.
Here is the Code of the servie

procedure TASSvc.ServiceExecute(Sender: TService);
var IniF: TIniFile;
    Prog : String;
    sList: TStringList;
    i: Integer;
begin
  sList:= TStringList.create;
  try
    IniF:= TIniFile.create(SystemDir+'\'+IniName);
    try
      IniF.ReadSection(IniSection, sList);
      for i:= 0 to sList.Count - 1 do
      begin
        Prog:= iniF.ReadString(IniSection, IntToStr(i), 'Error');
        ShellExecute(0, 'open', PChar(Prog), '', '', SW_Restore);
      end;
    finally
      IniF.free;
    end;
  finally
    sList.free;
  end;
end;

The service shall start programms and they are started. So it was started and it finished its job. But windows keeps telling that the service could not be started.

I tried ReportStatus and Before and AfterInstall a LogMessage, but nothing works, it still says no error reporting.

What can I do to let Windows know that the service worked?
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Commented:
try add code as:
 finally
  sList.free;
 end;
/////////////////
  while not Terminated do
    ServiceThread.ProcessRequests(True);
////////////////
end;

is cause you service thread not finish auto.

note: if you want service thread use gui proc like shellexcute , need set service.interactive := true.

Author

Commented:
Thank you, it worked like this.

I set interactive to true, the service itself woked allright.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial