Debugging Initialization Routines

Usually, the simplest way to use the debugger is to attach it to a running service. However, if you are debugging the service's initialization routines because the service won't start, you may not be able to connect the debugger to your application before the problem appears. To debug initialization routines, you can forego the debugger entirely and use the log file, or insert hard-coded breakpoints in your code. You can also set up a specialized environment within the debugger to debug initialization routines.

To use the debugger with an initialization routine, you must first edit the Windows NT Registry so that the service control manager will start both the debugger and the service. Set the value of the ImagePath environment variable to contain a command line that executes the service under a debugger. As an example, the following procedure shows how to debug the Schedule service (one of the default services of Windows NT Server).

    To debug the Schedule service
  1. Start the REGEDT32.EXE program and locate the following registry key:
    \\HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Schedule
     
  2. Change the associated value entry for ImagePath from:
    %SystemRoot%\System32\AtSvc.Exe
     

    to the following:

    msvc %SystemRoot%\System32\AtSvc.Exe
     
  3. In the Control Panel, choose Services. Select the Schedule service and choose StartUp. In the Log On As field of the Service dialog box, click Allow Service to Interact with Desktop. Click OK.
  4. In the Services dialog box, click Start. Visual C++ should start immediately.
  5. Activate the Visual C++ window to begin the debugging process.