Easier way to debug a Windows service

后端 未结 28 1620
春和景丽
春和景丽 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:21

    To debug Windows Services I combine GFlags and a .reg file created by regedit.

    1. Run GFlags, specifying the exe-name and vsjitdebugger
    2. Run regedit and go to the location where GFlags sets his options
    3. Choose "Export Key" from the file-menu
    4. Save that file somewhere with the .reg extension
    5. Anytime you want to debug the service: doubleclick on the .reg file
    6. If you want to stop debugging, doubleclick on the second .reg file

    Or save the following snippets and replace servicename.exe with the desired executable name.


    debugon.reg:

    Windows Registry Editor Version 5.00
    
    [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Image File Execution Options\servicename.exe]
    "GlobalFlag"="0x00000000"
    "Debugger"="vsjitdebugger.exe"

    debugoff.reg:

    Windows Registry Editor Version 5.00
    
    [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Image File Execution Options\servicename.exe]
    "GlobalFlag"="0x00000000"

提交回复
热议问题