How to Create an Installer for a Windows Service (.NET Framework) Using WiX

Written by Renato Ivanescu · September 17th, 2025 · 6min read

The operating system manages Windows Services, the background processes that can run continuously without user interaction.

In this article I’ll walk you through the necessary steps to create an installer for a Windows Service (targeting .NET Framework) using the WiX toolset. Additionally, I’ll show you an easier alternative using the Advanced Installer tool.

Create the Windows Service project

Let’s begin by creating the Windows Service project in Visual Studio:

  • Go to File - New - Project.
  • Select Windows Service (.NET Framework) from the list of templates.
  • Configure the project and set the appropriate .NET Framework version.
  • Click Create. The new project will appear in the Solution Explorer.

Configure the Service

Next, we have to define the service logic in the Service.cs file so we can specify what happens when you start, stop, or pause the said service.

In our example, the service will monitor a folder and log each new file added to the target folder. I’ve renamed the Service.cs file to FolderWatcherService.cs, for clarity.

public partial class FolderWatcherService : ServiceBase
{
    private FileSystemWatcher watcher;
    public FolderWatcherService()
    {
        InitializeComponent();
        this.ServiceName = "MyDemoService";  
    }
    protected override void OnStart(string[] args)
    {
        try
        {
            string pathToWatch = @"C:\Users\R\Desktop\TargetFolder";
            if (!Directory.Exists(pathToWatch))
                Directory.CreateDirectory(pathToWatch);
            watcher = new FileSystemWatcher(pathToWatch);
            watcher.Created += OnCreated;
            watcher.IncludeSubdirectories = false;
            watcher.EnableRaisingEvents = true;
            EventLog.WriteEntry("MyDemoService started and is watching the folder.");
        }
        catch (Exception ex)
        {
            EventLog.WriteEntry($"Error in OnStart: {ex.Message}", EventLogEntryType.Error);
        }
    }
    protected override void OnStop()
    {
        watcher?.Dispose();
        EventLog.WriteEntry("MyDemoService stopped.");
    }
    private void OnCreated(object sender, FileSystemEventArgs e)
    {
        string logPath = @"C:\MyServiceLog.txt";
        File.AppendAllText(logPath, $"[{DateTime.Now}] New file added: {e.FullPath}{Environment.NewLine}");
    }
}

Create the Setup Project

NoteBefore you create a WiX setup, install the HeatWave Visual Studio extension from the Visual Studio Marketplace.

To add the setup project:

- Navigate to FileNewProject.

- Select the MSI Package template from the list of templates.

MSI Package Template in Visual Studio

- Add the project's details, then click on Create.

- You should see the project already in the solution explorer.

Configure the Setup Project

Now, it’s time to configure the WiX setup project. The project template comes with three .wxs files. Each .wxs file has to be configured so they can define how the Windows Service is installed, registered, and managed on the user's machine.

First, let’s configure the Package.wxs file. It is the installer’s entry point where we set the package identity, version, and upgrade behavior. Also, we'll connect the installer’s Feature to the component group, which contains the service files.

<?xml version="1.0" encoding="utf-8"?>
<Wix xmlns="http://wixtoolset.org/schemas/v4/wxs"
     xmlns:util="http://wixtoolset.org/schemas/v4/wxs/util">
  <Package Id="MyCompany.MyService"
           Name="MyDemoService"
           Manufacturer="Caphyon"
           Version="1.0.0.0"
           Scope="perMachine">
    <MajorUpgrade DowngradeErrorMessage="A newer version is already installed." />
    <Feature Id="Main" Title="Main Feature">
      <ComponentGroupRef Id="ServiceComponents" />
    </Feature>
  </Package>
</Wix>

Next, we define the installation folder structure in the Folder.wxs file.

<?xml version="1.0" encoding="utf-8"?>
<Wix xmlns="http://wixtoolset.org/schemas/v4/wxs">
  <Fragment>
    <Directory Id="ProgramFiles64Folder">
      <Directory Id="DIR_Company" Name="MyCompany">
        <Directory Id="INSTALLFOLDER" Name="MyDemoService" />
      </Directory>
    </Directory>
  </Fragment>
</Wix>

Finally, we configure the ExampleComponents.wxs file to define what files will be installed inside the INSTALLFOLDER. Moreover, here we configure the service installation using:

- <ServiceInstall> → register the service and set its startup type, account, and description.

- <ServiceControl> → manages service start/stop during install/uninstall.

<?xml version="1.0" encoding="utf-8"?>
<Wix xmlns="http://wixtoolset.org/schemas/v4/wxs"
     xmlns:util="http://wixtoolset.org/schemas/v4/wxs/util">
  <Fragment>
    <ComponentGroup Id="ServiceComponents">
      <Component Id="cmp.ServiceExe" Directory="INSTALLFOLDER">
        <File Id="fil.ServiceExe"
              Source="$(var.MyDemoService.TargetPath)"
              KeyPath="yes" />
        <ServiceInstall Id="svc.Install"
                        Name="MyDemoService"
                        DisplayName="My Demo Service"
                        Description="Watches a folder and logs newly added files."
                        Type="ownProcess"
                        Start="auto"
                        ErrorControl="normal"
                        Account="LocalSystem" />
        <ServiceControl Id="svc.Control"
                        Name="MyDemoService"
                        Start="install"
                        Stop="both"
                        Remove="uninstall"
                        Wait="yes" />
      </Component>
    </ComponentGroup>
  </Fragment>
</Wix>

NoteMake sure your installer package is configured for per-machine installation. Remember: the user running the installer must have admin rights.

Build and Install

Build the project to generate the installer, then navigate to the project’s output directory and run the installer.

After installation, open the Services Console Manager. Your service should appear in the list with the configured name and description. You can add some files to the target directory and then check the log file to confirm the logging works.

Local Services in Services Console Manager

Creating the Service Installer using Advanced Installer

ImportantThe following steps require at least the Professional edition of Advanced Installer.

Advanced Installer provides a more user-friendly alternative to service installer creation through its intuitive graphical user interface. Here is a guide on how to create your service installer:

1. Start a new project:

- Launch Advanced Installer.

- On the Start Page, select Professional Project or higher and then click Create New Project.

Create new project in Advanced Installer

2. Add the service files:

- Navigate to the Files and Folders view.

- Add the files related to your service in the Application Folder.

Add Service Files in Advanced Installer

3. Define the new service:

- Go to the Services view.

- Click the New Service button.

- In the opened dialog, select the executable file of your service that you’ve added in the previous step.

Create New Service in Advanced Installer

5. Customize the Service (optional):

Once you add your service, you will find a wide range of customization options directly within the GUI. These allow you to configure several aspects of the service according to your requirements.

Customize the Services in Service Properties

Once you have finished configuring your service, click the Build button to generate the installer. Then, run it to install the service on your machine. That’s it. Your service should now appear in the Services Control Manager.

Conclusion

The WiX toolset stands as a fantastic option for creating an installer for a Windows Service (.NET Framework). It provides controls through its XML-based configuration. However, this approach demands a steeper learning curve.

Advanced Installer stands out as a far more intuitive solution. It streamlines the installer process creation through its graphical user interface. It makes the process significantly easier and more efficient.

You can explore the 30-day full-featured trial of Advanced Installer.


Download Advanced Installer Trial for free.

FAQs

How do I create an installer for a Windows Service (.NET Framework) using WiX?

Install the HeatWave extension for Visual Studio. Then, create an MSI Package project and edit the .wxs files. Use <ServiceInstall> to register the service and <ServiceControl> to manage its lifecycle.

ow do I create an installer for a Windows Service (.NET Framework) using Advanced Installer?

Start a new Professional Project or higher. Then, add the published service files to the Application Folder. Once added, go to the Services view to define and configure the service properties. The last step is to build the project to generate the installer.

How to configure a service in Advanced Installer?

In the Services view, select the service you’ve added and configure its properties directly within the Service Properties panel.

How do I set up a Windows Service targeting .NET Framework?

You have to inherit from ServiceBase, override OnStart/OnStop, set the service details and add the service logic in the Service.cs file.

Written by
See author's page
Renato Ivanescu

Renato is a technical writer for Advanced Installer and an assistant professor at the University of Craiova. He is currently a PhD. student, and computers and information technology are his areas of interest. He loves innovation and takes on big challenges.

Comments: