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.
thread.sleep(1000)
- Hershika Sharma