开发者

Problem stopping Windows Service from Installer Class. Events fire too late

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.

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.

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.

I have put messagebox's throughout the installer class BeforeInstall, BeforeUninstall (installer events), Install, Uninstall, Commit, Rollback (开发者_如何学JAVAoverridden methods) so I can see when these are called during the installation.

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.

I don't think this was the behaviour in earlier versions of .NET?

Has anyone come across this problem or have any suggestions?

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.


The try again message is shown by FilesInUse installer dialog. During InstallValidate action Windows Installer automatically detects files in use and prompts the user about them.

A solution is to stop (without removing) the service before InstallValidate action. This can be done through a custom action.

Please note that you cannot set a custom action before InstallValidate with Visual Studio. However, you can edit the MSI with Orca after it's generated and change the action sequence in InstallExecuteSequence table.

Most commercial setup authoring tools and WiX support custom sequences for your actions.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜