Connecting the Debugger to a Running Service
Running your service as a console application will not be useful if problems appear only when the application is run as a service. In this case, the best way to debug it is to start the application as a service and attach to the Visual C++ debugger while the service is running. To do this, start the service, obtain the process identifier, and then connect the debugger to the running process.
To find the process identifier and connect to the Visual C++ debugger
-
Install PVIEW.EXE from the Windows NT Resource Kit.
Caution This utility is not identical with the utility of the same name distributed with Microsoft Visual C++ and the Platform SDK. It is an extended version with more functionality. The correct version displays the window title Process Explode, rather than Process Viewer.
-
Start the service to be debugged. The service must be running before you can find its process identifier.
-
Start a command prompt or open an existing command prompt. Be sure that it is the only command prompt currently active.
-
Change directory to the installed location of PVIEW.EXE.
-
Type PVIEW.
-
In the drop-down list box near the top left of the PVIEW screen, find and select the process IDENTIFIER corresponding to CMD.EXE.
-
In the PVIEW dialog box, select Token. Click Process.
-
In Privileges, move SetDebugPrivilege from the Disabled box to the Enabled box. Click OK.
-
Connect Visual C++ to the running service. Note that when you use the process identifier from the Windows NT Server version of PVIEW.EXE, the process identifier is in decimal not hexadecimal. Start Visual C++ with the command line:
START MSDEV /P nnn
where nnn is the process identifier in decimal or hexadecimal notation.