Uninstall an MSI during during Inno Setup uninstal

2019-05-31 22:49发布

问题:

I install an MSI file as part of my Inno Setup install script. Is there a way to also uninstall it as part of the uninstall process for my program?

回答1:

The easiest way is to learn what is the GUID of that MSI package,

http://msdn.microsoft.com/en-us/library/aa370568(v=vs.85).aspx

as after installation, it will be registered under 'SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall (or its WOW64 one).

Once you know the GUID, it can be uninstalled by calling

MsiExec.exe /X{A879B90E-B62C-4DA4-9C3F-79A1A6CFAAF9}

Here {A879B90E-B62C-4DA4-9C3F-79A1A6CFAAF9} is an example for "Microsoft ASP.NET Web Pages - Visual Studio 2010 Tools".



回答2:

There are a lot variants to do it. With batch:

@echo off
  setlocal
    set "key=HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall"
    set raw=%key%\%%i
    for /f "tokens=7 delims=\" %%i in ('reg query %key%') do (
      if "%%i"=="Microsoft .NET Framework 3.5 SP1" (
        for /f "skip=4 tokens=2,*" %%j in ('reg query "%raw%" /v UninstallString') do (
          rem This command iniatlize uninstallation of .NET Framework
          start /wait "%%k"
        )
      )
    )
  endlocal
exit /b

With wmic:

wmic Product where Name="Microsoft .NET Framework 3.5 SP1" call Uninstall

And more.

P.S>"Microsoft .NET Framework 3.5 SP1" is here for just an example.