Click here to Skip to main content
13,901,147 members
Click here to Skip to main content
Add your own
alternative version

Tagged as


76 bookmarked
Posted 28 Sep 2011
Licenced CPOL

How to Debug or Test your Windows Service Without Installing it...

, 22 Nov 2012
Rate this:
Please Sign up or sign in to vote.
Debug or test your Windows Service without installing it...


When you develop a Windows Service and want to run or debug it, you get a message box with this message:

Cannot start service from the command line or a debugger.
A Windows Service must first be installed (using installutil.exe)
and then started with the ServerExplorer, Windows Services 
Administrative tool or the NET START command.

So for testing you have to first install it on your computer, but it is a long process and also boring because every time you make changes, you have to reinstall your service and test it again.


For debugging or testing your service without installing it, make changes in Program.cs like this.

static class Program
    static void Main()
        ServiceBase[] ServicesToRun;
        ServicesToRun = new ServiceBase[] 
	     new MyService() 

Change it to:

static class Program
    static void Main()
           ServiceBase[] ServicesToRun;
           ServicesToRun = new ServiceBase[] 
	        new MyService() 
           MyService myServ = new MyService();
           // here Process is my Service function
           // that will run when my service onstart is call
           // you need to call your own method or function name here instead of Process();

After adding #if and #else to your main fuction, now when you press F5 or run your service, it will not show you the previous message and simply run, so attach a break point to your method which will be called by the service when it will start. With the use of this code, you can simply debug your service without installing it.

For this no need to add any extra using directive (like using System.Data or using System.IO) to your class file. It will simply as it is.



This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Tejas Vaishnav
Software Developer (Senior)
India India
No Biography provided

You may also be interested in...


Comments and Discussions

QuestionSTAThread may be needed Pin
B. Clay Shannon24-May-16 8:00
professionalB. Clay Shannon24-May-16 8:00 
QuestionHow to stop the service? Pin
B. Clay Shannon24-May-16 6:58
professionalB. Clay Shannon24-May-16 6:58 
QuestionExplain Syntax Pin
IrishChieftain19-May-16 11:50
memberIrishChieftain19-May-16 11:50 
Questiona better solution PinPopular
יהושע אלפי23-Dec-15 5:29
memberיהושע אלפי23-Dec-15 5:29 
PraiseThanks for the article Pin
memberJEBA ANANTH VIJAYARAJAN25-Nov-15 23:25 
GeneralRe: Thanks for the article Pin
Tejas Vaishnav26-Nov-15 0:27
professionalTejas Vaishnav26-Nov-15 0:27 
QuestionGreat! Pin
Atroc3-Sep-15 5:34
memberAtroc3-Sep-15 5:34 
AnswerRe: Great! Pin
Tejas Vaishnav3-Sep-15 19:49
professionalTejas Vaishnav3-Sep-15 19:49 
QuestionCould we Pin
nomidis12-Dec-14 2:11
membernomidis12-Dec-14 2:11 
GeneralNice Trick Pin
granadaCoder21-Oct-14 10:51
membergranadaCoder21-Oct-14 10:51 
GeneralRe: Nice Trick Pin
Tejas Vaishnav29-Oct-14 19:44
professionalTejas Vaishnav29-Oct-14 19:44 
QuestionCopied article Pin
ursul_boa19-Nov-13 21:53
memberursul_boa19-Nov-13 21:53 
AnswerRe: Copied article Pin
Tejas Vaishnav20-Nov-13 2:21
professionalTejas Vaishnav20-Nov-13 2:21 
Questiongood article Pin
Jayesh Goyani21-Oct-13 2:15
memberJayesh Goyani21-Oct-13 2:15 
AnswerRe: good article Pin
Tejas Vaishnav21-Oct-13 2:46
professionalTejas Vaishnav21-Oct-13 2:46 
SuggestionMy vote of 1 and the reason why you should avoid such debugging/testing Pin
Lex Li5-Sep-13 22:29
professionalLex Li5-Sep-13 22:29 
GeneralRe: My vote of 1 and the reason why you should avoid such debugging/testing Pin
Tejas Vaishnav5-Sep-13 22:40
professionalTejas Vaishnav5-Sep-13 22:40 
GeneralMy vote of 1 Pin
Lex Li5-Sep-13 22:22
professionalLex Li5-Sep-13 22:22 
Questioncheated Pin
arshadssd23-Aug-13 3:22
memberarshadssd23-Aug-13 3:22 
AnswerRe: cheated Pin
Tejas Vaishnav25-Aug-13 20:10
professionalTejas Vaishnav25-Aug-13 20:10 
GeneralMy vote of 5 Pin
Member 76536939-Aug-13 12:41
memberMember 76536939-Aug-13 12:41 
GeneralRe: My vote of 5 Pin
Tejas Vaishnav11-Aug-13 18:44
professionalTejas Vaishnav11-Aug-13 18:44 
QuestionHave a doubt in myServ.Process() Pin
nirmalasudar18-Jun-13 19:13
membernirmalasudar18-Jun-13 19:13 
AnswerRe: Have a doubt in myServ.Process() Pin
Tejas Vaishnav21-Jun-13 2:42
professionalTejas Vaishnav21-Jun-13 2:42 
Questionwindow service Pin
sudheeshkumar6-Mar-13 1:13
membersudheeshkumar6-Mar-13 1:13 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Cookies | Terms of Use | Mobile
Web04 | 2.8.190306.1 | Last Updated 22 Nov 2012
Article Copyright 2011 by Tejas Vaishnav
Everything else Copyright © CodeProject, 1999-2019
Layout: fixed | fluid