title: Problem stopping Windows Service from Installer Class. Events fire too late
body: <p>I'm using Visual Studio 2010 with .NET 4.0. 
  I have a windows service that is installed from a Visual Studio Setup Project. In the setup project I have the RemovePreviousVersion property set to True.</p>
  
  <p>In the project that contains the service I have an installer class that will be used to stop the service when upgrading from a previous version. </p>
  
  <p>So when upgrading the software the service will already exist and could be running. If it is running then during the installation the installer prompts that the file is already in use and gives the option to Try Again, Continue or Exit Installation. At this stage I could stop the service manually and click Try Again and this will work. But I don't want the end user to have to do this.</p>
  
  <p>I have put messagebox's throughout the installer class BeforeInstall, BeforeUninstall (installer events), Install, Uninstall, Commit, Rollback (overridden methods) so I can see when these are called during the installation.</p>
  
  <p>When the install is run the prompt that the file is in use is displayed before any of the installer class code. Once I stop the service and click try again is will continue and the messagebox's in the install classes will be displayed. So the installer class is definately being called it's just too late in the process to actually do anything.</p>
  
  <p>I don't think this was the behaviour in earlier versions of .NET?</p>
  
  <p>Has anyone come across this problem or have any suggestions?</p>
  
  <p>I could try the InstallShiled LE Project that comes with Visual Studio 2010 if I needed to (not sure if that would give the same result) but would prefer to see if anyone knows a solution with the Visual Studio Setup Project if possible.</p>