Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Debugger.Launch() on windows service in Windows 8

After I installed Windows 8 perfectly legit statement like this doesn't work anymore:

#if DEBUG
    Debugger.Launch();
#endif

Service starts ignoring that thing. Yes, I am building the project in a debug mode.

if I change that to a Debugger.Break() - the service just fails, and still there's no dialog for attaching a debugger.

like image 971
iLemming Avatar asked Aug 20 '12 17:08

iLemming


People also ask

How do I connect to a debugger in Windows Service?

In the Options dialog box, choose Debugging, Symbols, select the Microsoft Symbol Servers check box, and then choose the OK button. The Processes dialog box appears. Select the Show processes from all users check box. In the Available Processes section, choose the process for your service, and then choose Attach.

How do I start debugging in Windows?

You can open most debugger windows while you are debugging your program. To see a list of debugger windows, set a breakpoint and start debugging. When you hit the breakpoint and execution stops, click Debug > Windows.

How do I debug a Windows Service without installing?

To debug without installing, add the code as follow, mainly #if (! DEBUG). You will be able to step through the code when you run the Windows Service without installing.


2 Answers

The secret lies in changing the registry key for the Visual Studio JIT debugger via the following:

reg add "HKCR\AppID\{E62A7A31-6025-408E-87F6-81AEB0DC9347}" /v AppIDFlags /t REG_DWORD /d 8 /f

Before making this change the value on my machine was 0x28. The above changes it to 0x8. In essence it removes the 0x20 flag.

If you search the Microsoft include files (WTypesbase.h) then you find the following:

#define APPIDREGFLAGS_IUSERVER_ACTIVATE_IN_CLIENT_SESSION_ONLY 0x20

Once you make this change then the JIT debugging window is displayed again. I believe that all of this relates to various session 0 security changes made by Microsoft.

Sourced from this post: http://forums.arcgis.com/threads/69842-Debugging-your-SOE-on-Windows-8

like image 56
blackdemon Avatar answered Sep 24 '22 23:09

blackdemon


Debugger.Launch would launch an application with a visual GUI. By default services do not interact with a desktop and thus anything they do cannot be "seen".

Support for interacting with the desktop has slowly been removed from Windows services ("Interact with the desktop" option has been removed from some Server versions for example). I would imagine they've continued this trend.

Windows Services by nature are not GUI applications, they can run before and after a user logs into a desktop and thus cannot show a GUI all the time. It's not generally a good idea to depend on an ability to have a GUI in a Service.

If what you want to do is debug a service, I suggest running it as a regular application so that you can do things like Launch and Debug. Shameless plug: you can see Developing Windows Services in Visual Studio for a way to write a service that supports that.

like image 25
Peter Ritchie Avatar answered Sep 23 '22 23:09

Peter Ritchie