RE: How to Debug a Windows Service



Did you write a service using .NET or win32?
I have always used win32. search www.codeproject.com for .NET examples.

I wrote a Windows Service in VC.NET 2005
I want to debug the solution.
I tried as mentioned in the following link.

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vbcon/html/vbconintroductiontontserviceapplications.asp

But, when I started the service I got a message box saying that the
service is being stopped.

The page you mention contains a link to 'debugging windows services' which
contains this explanation:

<snip>
Attaching to the service's process allows you to debug most but not all of
the service's code; for example, because the service has already been
started, you cannot debug the code in the service's OnStart method this way,
or the code in the Main method that is used to load the service.
</snip>

If all your code is in OnStart, you cannot debug it according to this.

What you could do is to is to print logging information to a text file
though that should at least give you some idea of what is happening inside
OnStart

And also I would like to know whether the application code is to be
written in the OnStart() method or not.

You can do it, but it is not mandatory. I have done it like that a couple of
times, but you don't have to. at least in win32 services.

One more problem that i faced while executing the Windows Service is,
if i try to pop-up a message box, i get "Stopping the Service" message
when i start the Service.

Is your service allowed to interact with the user interface? Otherwise you
will never see the dialog box. You should never put UI features in a service
anyway because it can easily lead to security problems. And even if you
provide UI features, they will be invisible if noone is logged in.

What I do when i need to debug service functionality is that I launch it in
the IDE, but with an argument that specifies it is running as a console
application instead of a service. that will instruct the application to
directly go to the function where the functionality of the program starts so
that the service stuff is skipped.

That ways you can debug all your code in the VS IDE. then , when you know it
works, you can start is as a service.

The platform SDK contains an example that does that exact same thing, but i
don't know if it is easy to do the same if you are using .NET to program a
service.

--

Kind regards,
Bruno.
bruno_nos_pam_van_dooren@xxxxxxxxxxx
Remove only "_nos_pam"


.



Relevant Pages

  • Re: How to Debug a Windows Service
    ... OnStart() method, then can you give me an idea of how to do it? ... I want to debug the solution. ... but it is not mandatory. ... directly go to the function where the functionality of the program starts so ...
    (microsoft.public.dotnet.languages.vc)
  • Re: Debug.exe for win32
    ... I'm no Windows expert, but I thought that debug was "optional" these ... > need this much for their headers and such. ... You can get a *little* win32 code into 64k. ...
    (alt.lang.asm)
  • Re: GenEnvironmentVariable and CreateProcess failures under XP
    ... > I am having truble figuring out how to debug a problem with VB6 program ... that shells other Win32 executables. ... CreateProcess to launch Notepad or other Win32 executables. ...
    (microsoft.public.vb.winapi)
  • Re: Who could tell me why the error address isnt the same?
    ... I use vc6.0,and when I set active project configuration to Win32 Debug,and ... What actually happened is that the strcpy was writing outside of the memory occupied by, into the rest of the stack. ... The difference between Debug and Release is that Debug build puts some extra data on the stack to help you debug easily. ...
    (microsoft.public.vc.mfc)
  • Re: dumb newbie question re unicode
    ... Platform is win32. ... Enter any name you would like to over there for example Unicode - Debug ... > the Add button I saw the platform as Win32. ...
    (microsoft.public.vc.mfc)