Easier way to debug a Windows service

后端 未结 28 1921
春和景丽
春和景丽 2020-11-22 15:36

Is there an easier way to step through the code than to start the service through the Windows Service Control Manager and then attaching the debugger to the thread? It\'s ki

28条回答
  •  时光取名叫无心
    2020-11-22 16:11

    I think it depends on what OS you are using, Vista is much harder to attach to Services, because of the separation between sessions.

    The two options I've used in the past are:

    • Use GFlags (in the Debugging Tools for Windows) to setup a permanent debugger for a process. This exists in the "Image File Execution Options" registry key and is incredibly useful. I think you'll need to tweak the Service settings to enable "Interact with Desktop". I use this for all types of debugging, not just services.
    • The other option, is to separate the code a bit, so that the service part is interchangable with a normal app startup. That way, you can use a simple command line flag, and launch as a process (rather than a Service), which makes it much easier to debug.

    Hope this helps.

提交回复
热议问题