Click here to Skip to main content
13,451,090 members (55,931 online)
Click here to Skip to main content
Add your own
alternative version


14 bookmarked
Posted 29 Apr 2008

Using Installutil to install a Windows Service and passing it parameters for the service

, 29 Apr 2008
Rate this:
Please Sign up or sign in to vote.
Pass parameters to InstallUtil so that it will use them when it installs the service into the Service Control Manager


There are many complaints about the InstallUtil that is used to install Windows Services that are built using .NET. Albeit the utility is not great, the most common complaint is that it can't pass paramters to the installer class that developers are forced to include in there service. This very simple sample shows that you can indeed pass paramters from the InstallUtil command line and access them from your installer class.


Windows services written in the .NET languages are encouraged to use the Installer class to register the service with the SCM (Service Control Manager). Then once the service is complete, a command line utility called InstallUtil is used to 'register' the new service with Windows. The InstallUtil looks in your .NET assembly for a class derived from System.Configuration.Install.Installer and executes it to perform the 'registration' (confusingly called installation). There are lots of questions on the 'net asking how to pass parameters from the command line of InstallUtil to this embedded Installer class so that the service can be registered with a specific account, service name, display name, ect. This sample will hopefully show how to do that.

Using the code

The service part of the sample does absolutely nothing as the code focuses on the embedded installer class. If you want a sample of how to code a Windows Service, there are thousands on this site and other site on the 'net. The quick part of the solution is the Context property of the Installer class. This property is a Dictionary collection, with every parameter of the command line given to Installutil in it. They are already broken out into Key and Value pairs, and it is just a matter of iterating the collection and using the keys and values as you need them.

Points of Interest

The one thing I wished I could do is default the logtoconsole parameter to false. The default is true and with it on the output on the console is quite verbose and confusing.


First posted April 29th, 2008


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


About the Author

Software Developer (Senior) Allstream ITS
Canada Canada
Senior software architect and developer for 18 years. Worked primarily with microsoft products, using them to integrate many 3rd party systems from numerous vendors into cohesive systems.

You may also be interested in...


Comments and Discussions

Questionsample code needed for the Installing Windows service with startup parameters using InstallUtil Pin
Member 49165220-Jul-11 7:19
memberMember 49165220-Jul-11 7:19 
GeneralBetter Pin
PIEBALDconsult29-Apr-08 13:21
memberPIEBALDconsult29-Apr-08 13:21 

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 | Terms of Use | Mobile
Web01-2016 | 2.8.180318.3 | Last Updated 29 Apr 2008
Article Copyright 2008 by jostros1
Everything else Copyright © CodeProject, 1999-2018
Layout: fixed | fluid