简体   繁体   中英

upgrade a service using MSI installer

I am upgrading my custom windows service using MSI installer. I am using C# code to start MSI process to first uninstall the service and then install new version.

I need to make sure that before MSI starts installing new version ,previous version is uninstalled . How do I add this check in c#?

I recommend using WIX to do this. A wrapper around MSI http://wixtoolset.org/documentation/

Make sure to increment the version as a best practice.

Key is to increment the Version attribute or set AllowSameVersionUpgrades="yes" and not change UpgradeCode="[your unique upgradecode here]". Make sure that the UpgradeCode attribute remains the same it has to be static so should not be set to * which will generate a random GUID.

<MajorUpgrade AllowSameVersionUpgrades="yes" DowngradeErrorMessage="A newer version of [ProductName] is already installed." />

 <Product
Name="Sample"
Id="*"
UpgradeCode="4c79fec3-a6b7-46eb-90d6-46688a7f1662"
Manufacturer="Sample"
Version="0.1.3.0"
Language="1033"> ... />

Your question is how to do this in C#

check the registry key HKLM:\\Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\

SC QUERY you probably just want to replace that part with C# code. I strongly advise against using most of the built-in Windows command-line programs.

I am using InstallSheild .. This issue was happening because by the time MSI installer could remove the SERVICE from registry, my code starts installing the new version of it.

So the MSI does remove the service from machine registry but because of the time lag in this process, new version installation fails. This happens in server machines mostly. Don't know the reason for it.

To fix it, i am now checking service existence before installation using sc query servicename and so while service exists I am doing thread.sleep(1000)

Please share a better approach if any. But I have to do it using InstallSheild only.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM