Search code examples
c#command-lineregistryuninstallationuninstallstring

Uninstall String from Registry Always the Same?


I just need a little reassurance here. I am creating a basic C# program that, among other things, will uninstall and reinstall the most current version of a program (I can't build this functionality into the program itself). The way I am doing it is by:

MsiExec.exe /X{[UninstallString]} /passive

in a command prompt process. I have a couple of questions:

  1. Obviously you don't know the history of the program (I don't either to tell you the truth), but is that uninstall string generally the same every time for every version? Does it change?
  2. Is there any possible way that the uninstallstring could accidentally be a different program's string on another computer? I don't want to uninstall anything else.

Basically I just want to know if this is safe. If not, or if there is a better way to do this programatically, let me know! Thanks!


Solution

  • See "To uninstall a product"; you can specify a ProductCode, which is globally unique by definition. So you won't uninstall any other product. You can also specify the msi filename, but you have to be more carefull, as it can happen that different products get the same filename. So using the ProductCode is the best way to do this.

    See also What are Upgrade, Product and Package Codes used for?