Skip to main content
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Download Microsoft Edge
More info about Internet Explorer and Microsoft Edge
e
Read in English
Read in English
Edit
Share via
Facebook
LinkedIn
Email
Debugging a Service
In this article
You can use any one of the following methods to debug your service.
Use your debugger to debug the service while it is running. First, obtain the process identifier (PID) of the service process. After you have obtained the PID, attach to the running process. For syntax information, see the documentation included with your debugger.
Call the DebugBreak function to invoke the debugger for just-in-time debugging.
Specify a debugger to use when starting a program. To do so, create a key called Image File Execution Options in the following registry location:
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion
Create a subkey with the same name as your service (for example, MYSERV.EXE). To this subkey, add a value of type REG_SZ, named Debugger. Use the full path to the debugger as the string value. In the Services control panel applet, select your service, click Startup and check Allow Service to Interact with Desktop. The service must be an interactive service, or else the debugger cannot run on the default desktop. Note that this technique is no longer supported as of Windows Vista because all services are run in session that is reserved exclusively for services and does not support displaying a user interface.
Use Event Tracing to log information.
To debug the initialization code of an auto-start service, you will have to temporarily install and run the service as a demand-start service.
At times, it may be necessary to run a service as a console application for debugging purposes. In this scenario, the StartServiceCtrlDispatcher function will return ERROR_FAILED_SERVICE_CONTROLLER_CONNECT. Therefore, be sure to structure your code such that service-specific code is not called when this error is returned.
Debugging a Service Application
Debugging Tools for Windows
Feedback
Was this page helpful?
Provide product feedback
|
Get help at Microsoft Q&A
Feedback
Coming soon: Throughout 2024 we will be phasing out GitHub Issues as the feedback mechanism for content and replacing it with a new feedback system. For more information see: https://aka.ms/ContentUserFeedback.
Submit and view feedback for
This product
This page
View all page feedback
Additional resources
(CCPA) Opt-Out Icon
Your Privacy Choices
●
●
●
●Previous Versions
●Blog
●Contribute
●Privacy
●Terms of Use
●Trademarks
●© Microsoft 2024
Additional resources
In this article
(CCPA) Opt-Out Icon
Your Privacy Choices
●
●
●
●Previous Versions
●Blog
●Contribute
●Privacy
●Terms of Use
●Trademarks
●© Microsoft 2024