How do you debug an installed Windows service?

I know how to connect a debugger to a Windows service, but I cannot connect to the one that is installed and started by the window installer. I tried:

  • Setting Thread.Sleep (TimeSpan.FromSeconds (30)); at the beginning of on-start, but when I try to connect in Visual Studio, the service name does not appear as an option. This works fine, the service name is displayed in the list, but this is not the case with the installer.

  • Configuring Debugger.Break and Debugger.Launch. They don’t do anything.

What can I do to debug my service?

Update:

I added Thread.Sleep for 30 seconds as the first line of the service, and when the installer tells me what it should do when it fails, I start the service in the list of services (since it has not been deleted) and it does not work instantly without 30 seconds of waiting. The files that it installs are the last (they have the correct modified time). A 30 second pause occurs if I start the same client from my test application in the same project, but for some reason the installer is screwing something.

I'm really not sure how to debug this, and it is disappointing that this service worked correctly.

Answer:

Checking the application log showed me the exception that was thrown. It turned out that I accidentally mounted the file in my installer, which explains why none of my debugging methods worked. As soon as I restored the file, I was able to connect with the visual studio as usual (using a 30 second pause to give me time).

+4
source share
3 answers
  • In services.msc, right-click on your service and select properties.
  • On the tab "Login" is allowed to interact with the desktop.
  • Add something like Debug.Assert(false, "attach now"); to your OnStart method in ServiceBase.
  • Attach to the process and click ignore in the confirmation dialog box.

Edit 1: Things that happen to me in a certain order;

If it worked, is it possible that it no longer works as the same user? The new user may not have the same permissions or changes allowed.

Use the event viewer to check the application log.

If a problem occurs during the installation process, there may be some information in InstallUtil.InstallLog or {assemblyname} .InstallLog, they will be in the same directory as .exe.

I do this from my Linux laptop, so I'm a bit fuzzy.

Edit 2:

In the service manager, right-click on your service and select properties. Make sure the service points to the correct executable; I saw the assembly steps of the assembly doing funky things.

+2
source

When connecting the VS debugger, make sure that the "Show processes from all users" checkbox is selected. Your service is probably running under a local service or local system.

+1
source

Here are some links to help you troubleshoot starting a Windows service in production where you do not have VS.NET. It can also be used in Dev.

+1
source

Source: https://habr.com/ru/post/1306425/


All Articles