title: Installing multiple instances of the same windows service on a server
body: <p>So we've produced a windows service to feed data to our client application and everything is going great.  The client has come up with a fun configuration request that requires two instances of this service running on the same server and configured to point at separate databases.</p>
  
  <p>So far I haven't been able to get this to happen and was hoping my fellow stackoverflow members might be able to give some hints as to why.</p>
  
  <p>Current setup:</p>
  
  <p>I've set up the project that contains the windows service, we'll call it AppService from now on, and the ProjectInstaller.cs file that handles custom installation steps to set the service name based on a key in the App.config like so:</p>
  
  <pre><code>this.serviceInstaller1.ServiceName = Util.ServiceName;
  this.serviceInstaller1.DisplayName = Util.ServiceName;
  this.serviceProcessInstaller1.Account = System.ServiceProcess.ServiceAccount.LocalSystem;
  </code></pre>
  
  <p>In this case Util is just a static class tha tloads the service name from the config file.</p>
  
  <p>From here forward I have tried two different ways to get both services installed and both have failed in an identical way.</p>
  
  <p>The first way was to simply install the first copy of the service, copy the installed directory and renamed it, and then ran the following command after modifying the app config to change the desired service name:</p>
  
  <pre><code>InstallUtil.exe /i AppService.exe
  </code></pre>
  
  <p>When that didn't work I tried to create a second installer project, edited the config file and built the second installer.  When I ran the installer it worked fine but the service did not show up in services.msc so I ran the previous command against the second installed code base.</p>
  
  <p>Both times i received the following output from InstallUtil (relevant parts only):</p>
  
  <blockquote>
    <p>Running a transacted installation.</p>
    
    <p>Beginning the Install phase of the installation.</p>
    
    <p>Installing service App Service Two...
    Service App Service Two has been successfully installed.
    Creating EventLog source App Service Two in log Application...</p>
    
    <p>An exception occurred during the Install phase.
    System.NullReferenceException: Object reference not set to an instance of an object.</p>
    
    <p>The Rollback phase of the installation is beginning.</p>
    
    <p>Restoring event log to previous state for source App Service Two.
    Service App Service Two is being removed from the system...
    Service App Service Two was successfully removed from the system.</p>
    
    <p>The Rollback phase completed successfully.</p>
    
    <p>The transacted install has completed.
    The installation failed, and the rollback has been performed.</p>
  </blockquote>
  
  <p>Sorry for the long winded post, wanted to make sure there is enough relevant information.  The piece that so far has me stumped is that it states that the installation of the service completes successfully and its only after it goes to create the EventLog source that the NullReferenceException seems to get thrown.  So if anyone knows what I'm doing wrong or has a better approach it would be much appreciated.</p>