Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
504 views
in Technique[技术] by (71.8m points)

wix - How to uninstall with msiexec using product id guid without .msi file present

I'm trying to automate the uninstallation of packages created using WiX for the purposes of changing the installed software stack & configuration without reprovisioning a whole OS. Eventually I'll use powershell scripting to do this but at the moment I can't seem to get my test package to uninstall interactively with cmd.

If I run:

msiexec /x '{A4BFF20C-A21E-4720-88E5-79D5A5AEB2E8}'

msiexec /x A4BFF20C-A21E-4720-88E5-79D5A5AEB2E8

I get:

"The installation package could not be opened. Verify that the package exists and that you can access it, or contact the application vendor to verify that this is a valid Windows Installer Package."

If I run: msiexec /x {A4BFF20C-A21E-4720-88E5-79D5A5AEB2E8}

I get:

"This action is only valid for products that are currently installed"

I've looked at the windows installer guide, the WiX documentation, msiexec documentation and used orca to go over the .msi myself but I've not really found anything that gives a clear picture of how an uninstall is processed. Is the .msi file required and if not then why does windows installer seem to think it is when given a GUID?

The WiX code for the .msi installer is:

<?xml version='1.0' encoding='windows-1252'?>
<Wix xmlns='htp://schemas.microsoft.com/wix/2006/wi' >

  <!--DO NOT COPY / PASTE THE PRODUCT ID GUID BELOW TO YOUR OWN WIX SOURCE -->

  <Product Id='A4BFF20C-A21E-4720-88E5-79D5A5AEB2E8' Language='2057' 
           Manufacturer='COMPANYNAME IT-Operations' 
           Name='COMPANYNAMEServerListener' Version='1.0.0' 
           UpgradeCode='PUT-GUID-HERE'>

   <Package Id='*' Manufacturer='COMPANYNAME IT-Operations' Compressed='yes' />
   <Media Id='1' Cabinet='COMPANYNAMEServerListener.cab' EmbedCab='yes' />

    <Directory Id='TARGETDIR' Name='SourceDir'>
      <Directory Id='ProgramFilesFolder' Name='PFiles'>
      <Directory Id='COMPANYNAME' Name='COMPANYNAME'>
        <Directory Id='INSTALLDIR' Name='COMPANYNAMEServerListener'>
        <Component Id='MainExecutable' Guid='*' >
          <File Id='COMPANYNAMEServerListener.exe' 
                Source='COMPANYNAMEServerListener.exe' Vital='yes' 
                KeyPath='yes' />
          <ServiceInstall 
            Id='COMPANYNAMEServerListenerInstall'
            DisplayName='COMPANYNAMEServerListener'
            Description='Accepts and discards TCP connections on port 28028 to indicate that this server is alive and ready to be controlled'
            Name='COMPANYNAMEServerListener'
            Account='NT AUTHORITYLocalService'
            ErrorControl='normal'
            Start='auto'
            Type='ownProcess'
            Vital='yes'           
          >
            <ServiceDependency Id='tcpip'/>
          </ServiceInstall>
          <ServiceControl Id="StartService" Start="install" Stop="both" Remove="uninstall" Name="COMPANYNAMEServerListener" Wait="yes" />
        </Component>
        </Directory>
        </Directory>
      </Directory>
      </Directory>

    <Feature Id='Complete' Level='1' >
      <ComponentRef Id='MainExecutable' />
    </Feature>

    <CustomTable Id ="COMPANYNAMEMetadata">
      <Column Id="Property" Type="string" Category="Identifier" PrimaryKey="yes"/>
      <Column Id="Value" Type="string"/>
      <Row>
      <Data Column="Property">InstallString</Data>
      <Data Column="Value">/qn</Data>
      </Row>
    </CustomTable>


  </Product>
</Wix>
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

"Reference-Style" Answer: This is an alternative answer to the one below with several different options shown. Uninstalling an MSI file from the command line without using msiexec.


The command you specify is correct: msiexec /x {A4BFF20C-A21E-4720-88E5-79D5A5AEB2E8}

If you get "This action is only valid for products that are currently installed" you have used an unrecognized product or package code, and you must find the right one. Often this can be caused by using an erroneous package code instead of a product code to uninstall - a package code changes with every rebuild of an MSI file, and is the only guid you see when you view an msi file's property page. It should work for uninstall, provided you use the right one. No room for error. If you want to find the product code instead, you need to open the MSI. The product code is found in the Property table.


UPDATE, Jan 2018:

With all the registry redirects going on, I am not sure the below registry-based approach is a viable option anymore. I haven't checked properly because I now rely on the following approach using PowerShell: How can I find the product GUID of an installed MSI setup?

Also check this reference-style answer describing different ways to uninstall an MSI package and ways to determine what product version you have installed: Uninstalling an MSI file from the command line without using msiexec


Legacy, registry option:

You can also find the product code by perusing the registry from this base key: HKEY_LOCAL_MACHINESOFTWAREMicrosoftWindowsCurrentVersionUninstall . Press F3 and search for your product name. (If it's a 32-bit installer on a 64-bit machine, it might be under HKEY_LOCAL_MACHINESOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall instead).

Legacy, PowerShell option: (largely similar to the new, linked answer above)

Finally, you can find the product code by using PowerShell:

get-wmiobject Win32_Product | Format-Table IdentifyingNumber, Name

enter image description here

Similar post: WiX - Doing a major upgrade on a multi instance install (screenshot of how to find the product code in the MSI).


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...