1

Asking similar question because no one answered previous question asked

I have a solution with a class library project, a WPF project (start up project) and a Windows Service project. I would like to create one installer so that when the user installs the application then both WPF (UI) and Windows service gets installed.

Most of the resources I found online only talk about one or another but not both. For example this:.

I checked some question on stackoverflow but either they are not answered by any one or vague answers like this question or this one.

Any suggestion how to achieve this?

Karan
  • 752
  • 2
  • 13
  • 34
  • This is a bad idea imo. https://stackoverflow.com/questions/1542656/wix-to-install-multiple-applications – Andy Apr 08 '19 at 16:57
  • Possible duplicate of [Wix to Install multiple Applications](https://stackoverflow.com/questions/1542656/wix-to-install-multiple-applications) – Dour High Arch Apr 08 '19 at 17:22
  • There's nothing at all wrong with wanting to do this. My project has been doing this for years. Answer provided below. – Matt Davis Apr 11 '19 at 06:03

1 Answers1

0

I'm not an expert on various installer solutions, but yes, this can be done. I know because my project does it.

We've historically used InstallShield, but we are actively moving to InstallAware for reasons unrelated to this discussion. Frankly, I suspect any installer solution (e.g., InstallShield, InstallAware, Wix, etc.) could be used to do this providing that it has the means to execute a batch script as part of the install process (more on this in a moment). In fact, while we are building our new installer using InstallAware, we are temporarily delivering our WPF-based application and Windows Service using a WinZip self-extracting executable. The WinZip self-extractor puts the WPF application in the C:\Program Files\<application>\<version> folder, puts the Windows Service in the C:\Program Files\<application>\Common folder, and then installs and starts the Windows Service.

The trick to all of this, of course, is getting the Windows Service installed. Initially, we used the InstallUtil.exe utility to do this, but we had to err on the side of caution and deliver it with our installer because we couldn't verify whether or not we could depend on the utility being available on the target system. At some point along the way, I read this answer by @Marc Gravell. This provided the springboard to my answer here, which provides detailed instructions for having your Windows Service install itself from the command line without the need for InstallUtil.exe.

So as a set of instructions...

  1. Update your Windows Service based on the details here.
  2. Create a .bat file with the following commands:

    cd <PathToWindowsServiceInstallationFolder>
    <YourWindowsService>.exe -install

  3. Build the installer for your WPF Service and Windows Service. Note that this should focus on deploying the files to their correct locations. You'll need to include the .bat file as part of the installer. If your installer solution allows you to copy files to a temporary folder that gets deleted at the end of the installation process, copy the .bat file to that location since you won't need it after the installer is finished.

  4. Finally, execute the .bat file from your installer during installation. This will install the Windows Service.

It's really not that complicated all things considered.

The one thing to be aware of is that your users should plan on running the installer as an administrator. Since installing the Windows Service updates the registry, users without administrative privileges might run into problems when trying to install your product.

HTH

Matt Davis
  • 45,297
  • 16
  • 93
  • 124
  • Thanks @Matt this is exactly what I was looking. I will follow these steps and let you know if find something new. – Karan Apr 11 '19 at 13:56