in

ASP.NET Weblogs

Ian Stallings: web log

official chicken™

Installing Windows Service Using .msi

When I created a windows service using .Net I also created an installer project using VS.net 2002's built in setup project. This worked fine if all I wanted to do was copy my service.exe and service.config file to the target machine but the user would still have to run the InstallUtil utility provided by Microsoft to install the service itself. After searching on the web I didn't find anything about how to accomplish this so I thought I'd share how I did it:

In my setup project I added the InstallUtil.exe to my target files under Application Folder along with it's .config file. Under custom actions I created a custom action for Install. I call InstallUtil.exe and set the Arguments property to "[TARGETDIR]\service.exe". Then I set the InstallerClass property to False. I do the same thing for the Unistall but I set the Arguments property to /u "[TARGETDIR]\services.exe".

* warning *
Now that all being said it will work fine if the service is not already installed. If it is the InstallUtil.exe will throw an error and the install will fail. Easy to work around but only the developer will know why and how to fix it.

Everyone - Please let me know if you come up with a better or easier way to accomplish this.

Comments

 

Morten Abrahamsen said:

If I remember correctly you can enable a custom installer action in the installation project that invokes any ".Net installers" in the assembly.

The installutil simply searches your assembly for installers and perform the required actions.

I'm not sure whether redistributing installutil is even legal ...


Good luck :)
January 7, 2004 5:58 PM
 

Ian Stallings said:

Good point. Luckily I'm not redistributing it, just using it internally to automate the installation.

I'll have to look into what you said above about the using custom action only. Thanks :)
January 7, 2004 6:16 PM
 

Adam Weigert said:

still, its not recommended to do it this way ... there is a ServiceInstaller class that you can inherit from. Check the MSDN documentation it will have examples. INSTALLUTIL is not meant for deployment. Plus it ups the size of package by more than a small installer class would.
January 7, 2004 8:15 PM
 

TrackBack said:

January 7, 2004 11:31 PM
 

Thomas Freudenberg said:

You may extend your service class, so it can register itself via command line parameters: http://thomasfreudenberg.com/blog/archive/2003/10/09/218.aspx
January 8, 2004 2:03 AM
 

Adam said:

I've seen a few people asking about this lately, and there is a very easy way to do it.

In your setup project, create a custom Install action, that runs your Service project output, and set its argument to be "/install".

Do the same thing for uninstall with the argument "/uninstall".

As long as you added an installer class to your service, it will automatically install and uninstall your your service for you. No need to use InstallUtil.
January 8, 2004 9:37 AM
 

Ian Stallings said:

Thanks for the feedback! I'll update my project and make sure I post the results. It smelled so I suspected it should be easier. Reading more of the docs up front would have helped though. I dropped the ball. But fortunately this blog and you comments helped.
January 8, 2004 10:14 AM
 

Shaun said:

When the .NET framework is installed on the Client PC a copy of InstallUtil.exe is included in the C:\WINDOWS\MICROSOFT.NET\FRAMEWORK\<VERSION\ folder.

Simply set your path to that folder and type InstallUtil <YourServiceName>
January 23, 2004 11:38 AM
 

Ian Stallings said:

Yes, read my latest post from Thursday January 8th and you'll see I found the correct way to do this. No need to add InstallUtil.exe to the package.
January 23, 2004 11:54 AM
 

Rob said:

Adam's comments at totally spot on. MS documentation is complete rubbish. Even suggests using LocalService.... which usually doesn't exist.
February 3, 2004 12:50 PM
 

Ed said:

Any thing new since last posting?
March 8, 2004 3:15 PM
 

Ian Stallings said:

No, it's working fine now:

http://weblogs.asp.net/jmoon/archive/2004/01/08/48629.aspx


I was doing the process incorrectly.
March 9, 2004 11:08 AM
 

Tim said:

FWIW Adam's suggestion worked perfectly for me

January 3, 2008 1:45 AM
 

Sohjiroz said:

Thanks Adam, is nice to count with people who wants to share  good information, i own you one

February 1, 2008 12:11 PM
 

Moms work from home. said:

Work at home moms. Top work at home moms.

August 21, 2008 8:44 AM

Leave a Comment

(required)  
(optional)
(required)  
Add