I am currently writing a Service application and have been having a few issues ( https://plus.google.com/108221563060569563805/posts/c4nVPaK6hth ). I decided to use OutputDebugString ( as the debug method I was using did not appear to be catching an error ).

I am currently writing a Service application and have been having a few issues ( https://plus.google.com/108221563060569563805/posts/c4nVPaK6hth ). I decided to use OutputDebugString ( as the debug method I was using did not appear to be catching an error ).

I stuck the OutputDebugString at the top and bottom of every relevant procedure, So:

ServiceAfterInstall, ServiceStart and ServiceStop

... and in the DPR at the point when everything is being constructed.

I don't seem to be able to get beyond Starting the Service.

When I install the Service the OutputDebugString debug appears as I would expect. However, as soon as I start the Service it is stopped automatically with a message: 

"The Unity Express Alerts service on Local Computer started and then stopped. Some services stop automatically if they are not in use buy other services or programs." 

I looked in the Event Viewer and the log states "Service failed on start: list index out of bounds[0]". 

However, why do I not see any OutputDebugString debug for ServiceStart AT ALL. I have placed my OutputDebugString line at the VERY TOP of that routine.

Any help would be appreciated

Thanks
Tony

Comments

  1. Hi Tony, if you are using the debugging code that I sent you before, you should disable it while installing/running it as a real service, meaning that you should not create/show the form in that case. In general, I use a simple {$IFDEF} for that.
    Two other important things when developing Windows services:
    1) Your TService.ServiceStart() should set the var parameter named "Started" to true. That's how the service controller knows that your service started.
    2) In case of any problems while running/installing the service, always check the user credentials. Always install as administrator and, in case of some problems while trying to start the service, change the service's "Logon" user to some user with admin privileges. If you need access to some network resource in a windows domain (DB, LDAP, mail servers come to my mind), it is a good idea to use some domain user with full local admin privileges.

    ReplyDelete
  2. Alexandre Machado I ran that code it was great and with a bunch of breakpoints I managed to resolve my initial problem, but I still get this "list index out of bounds[0]" now and that is when I run without the form ( commented out totally ). The weird thing is this NEVER happens when I run it in debug with your debug form.

    1) I am setting Started to True in ServiceStart(). I notice your code calls Started := True and then FOnStart(), but mine creates all the objects and then sets Started to True. I am wondering if this has an relevance? 
    2) I am installing the Service from a command prompt that is being run as Administrator. In the past ( about 5 years ago, when I last did a Service ), that has been sufficient.?

    The only thing my Service does where it needs user access of any kind is to read a SQL Server table and the user login and password I use will suffice for that.

    So, I really don't get what is wrong

    ReplyDelete
  3. I think you are doing (1) and (2) correctly, so this is something else...

    ReplyDelete
  4. Start on the other side.
    In each step, commit to your version control system so you can roll back to a point it still works
    1. Create a new empty service with logging.
    2. Verify in the log it installs, starts, stops, restarts, uninstalls, etc.
    3. Step by step add logic from your current service, and repeat 2 for each step.

    ReplyDelete
  5. Jeroen Wiert Pluimers I think you may be right. I was kind of thinking I might have to do this, but hoping I might avoid it at the same time ;-(

    ReplyDelete
  6. My day just gets worse with this damn Service. It's driving me nuts.
    I have OutputDebugString statements in ServiceAfterInstall and ServiceStart.

    In debug mode with Alexandre's debug form it works faultlessly, and I see all of the OutputDebugStrings.

    When I take out this form and rebuild it ( no other changes at all !! ); it starts; doesn't fail, but I never see any OutputDebugString's for ServiceStart and there are no faults in the EventViewer and it is NOT failing anywhere. I suspect it's actually NOT starting as it does not product any of our own debug neither does it do what it supposed to do.

    Bloody hell, has writing Services in Delphi descended into this living hell since the last time I wrote one ?? Or am I just seriously unlucky.

    If anyone has any clue's as to why I am not getting OutputDebugStrings and NO fails I would be eternally grateful and may even consider having their children..... ;-)

    Am just going into the kitchen to swear now .... back in 5 .....

    ReplyDelete
  7. May or may not help.  I use SVCOM for my Windows Services.  It has it's own Application object.  At one point I had visual forms and the VCL application object running for debugging/development then switched to SVCOM.  I forgot about the VCL Application object and I was in a world of hurt for a while.    Take a look at your project source and see if you have anything out of the ordinary in there.

    ReplyDelete
  8. Hi Tony Danby I had this ODS issues once. I'm not sure if it happened because of an old DebugView version, or permissions of the user running the server. Anyway, you can use something else like a log file in this case. Whenever OutputDebugString doesn't work, a log file may save you!

    ReplyDelete

Post a Comment