Debug a service application

How do you debug a service application? If you run it from in delphi it never makes it to any of my code.
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

If you set delphi as your active debugger, you should be able to put a line of code 'DebugBreak' to set a run-time breakpoint in your code.

I use this all the time from C in multithreaded programs, but I'm not sure how well it'll work in Delphi.

(you might have to include debugging information in the .EXE using some project linker options)

essbbAuthor Commented:
so there isnt a simple way to 'step' through the code from the IDE?
Not that I know of...

In order to debug the service (while it is running as a service application) the host (the windows SCM - service control manager) must execute the .EXE and call the ServiceMain() function that is registered by the .EXE.

Because the host must execute the .EXE, you cannot 'step' through it because someone else (the host) took the first step.

Using the windows api call DebugBreak() will cause the system default debugger to execute and will allow you to step through the source code if the proper debugging symbols are present in the .EXE (or the debugger is smart enough to know where to find them).

I've just tested this, and it seems that even DebugBreak won't get you into the service (on my machine).

This is what MS has to say about it...

Debugging a Service
You can use the following methods to debug your service.

<LI>Use your debugger to debug the service while it is running. First, obtain the process identifier (PID) of the service process. This information is available from the <B>PView</B> application. After you have obtained the PID, attach to the running process. For syntax information, see the documentation included with your debugger.</LI>
<LI>Call the <B>DebugBreak</B> function to invoke the debugger for just-in-time debugging.<LI>
<LI>Specify a debugger to use when starting a program. To do so, create a key called Image File Execution Options in the following registry location:
<B>HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion</B>

Create a subkey with the same name as your service (for example, <B>MYSERV.EXE</B>). To this subkey, add a value of type REG_SZ, named <B>Debugger</B>. Use the full path to the debugger as the string value. In the Services control panel applet, select your service, click <B>Startup</B> and check <B>Allow Service to Interact with Desktop.</B></LI>

<B>Note</B>  To debug the initialization code of an auto-start service, you will have to temporarily install and run the service as a demand-start service.

good luck!

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
essbbAuthor Commented:
Thanks for the help
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.