Debugging a Windows NT Service

ID: Q170738


The information in this article applies to:


SUMMARY

Debugging a Windows NT service can be done in several ways. You can debug a service while it is running by attaching to the process ID of the Service through a debugger such as NTSD or WINDBG. You can also set Windows NT so that it will start the process in a debugger when you start the service.

These techniques are useful for different debug scenarios. This article discusses the steps that you need to take when you want to debug a service during the initialization.


MORE INFORMATION

In order to set up Windows NT so that it will start the Service in a debugger, the following registry key needs to be set during the Service initialization:

WARNING: Using Registry Editor incorrectly can cause serious, system-wide problems that may require you to reinstall Windows NT to correct them. Microsoft cannot guarantee that any problems resulting from the use of Registry Editor can be solved. Use this tool at your own risk.

  1. Start Registry Editor and locate the following Registry subkey in the HKEY_LOCAL_MACHINE subtree:
    
          SOFTWARE\Microsoft\Windows NT\CurrentVersion\Image File Execution
          Options 


  2. Create a subkey with the name of your Service executable (for example, Myservice.exe)


  3. To this subkey, add the REG_SZ value called Debugger and the full path to the debugger you want to use, but omit the ".exe" extension. You can add any command-line option for the debugger as well.


  4. Close Registry Editor.


  5. Start the Service


The debugger will start when the image for the Service executable is loaded into memory.

For additional information on Windows NT debuggers, please see the following articles in the Microsoft Knowledge Base:
Q121652 List of Debuggers Supported with Windows NT

Q121434 Specifying the Debugger for Unhandled User Mode Exceptions


Keywords          : NTSrvWkst 
Version           : 4.0
Platform          : winnt 
Issue type        : kbhowto 

Last Reviewed: February 20, 1999