How to uninstall with msiexec using product id gui

2019-01-17 07:28发布

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 AUTHORITY\LocalService'
            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>

7条回答
趁早两清
2楼-- · 2019-01-17 07:44

you need /q at the end

MsiExec.exe /x {2F808931-D235-4FC7-90CD-F8A890C97B2F} /q
查看更多
神经病院院长
3楼-- · 2019-01-17 07:45

There's no reason for the {} command not to work. The semi-obvious questions are:

  1. You are sure that the product is actually installed! There's something in ARP/Programs&Features.

  2. The original install is in fact visible in the current context. It looks as if it might have been a per-user install, and if you are logged in as somebody else now then it won't know about it - you'd need to log in under the same account as the original install.

  3. If the \windows\installer directory was damaged the cached file would be missing, and that's used to do the uninstall.

查看更多
你好瞎i
4楼-- · 2019-01-17 07:45

msiexec.exe /x "{588A9A11-1E20-4B91-8817-2D36ACBBBF9F}" /q

查看更多
你好瞎i
5楼-- · 2019-01-17 07:49

The good thing is, this one is really easily and deterministically to analyze: Either, the msi package is really not installed on the system or your are doing something wrong. Of course the correct call is:

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

(Admin rights needed of course- With curly braces without any quotes here- quotes are only needed, if paths or values with blank are specified in the commandline.)
If the message is: "This action is only valid for products that are currently installed", then this is true. Either the package with this ProductCode is not installed or there is a typo.

To verify where is the fault:

  1. First try to right click on the (probably) installed .msi file itself. You will see (besides "Install" and "Repair") an Uninstall entry. Klick on that.
    a) If that uninstall works, your msi has another ProductCode than you expect (maybe you have the wrong WiX source or your build has dynamic logig where the ProductCode changes).
    b) If that uninstall gives the same "...only valid for products already installed" the package is not installed (which is obiously a precondition to be able to uninstall it).

  2. If 1.a) was the case, you can look for the correct ProductCode of your package, if you open your msi file with Orca, Insted or another editor/tool. Just google for them. Look there in the table with the name "Property" and search for the string "ProductCode" in the first column. In the second column there is the correct value.

There are no other possibilities.

Just a suggestion for the used commandline: I would add at least the "/qb" for a simple progress bar or "/qn" parameter (the latter for complete silent uninstall, but makes only sense if you are sure, it works).

查看更多
兄弟一词,经得起流年.
6楼-- · 2019-01-17 07:49

Try this command msiexec /x {product-id} /qr

查看更多
贼婆χ
7楼-- · 2019-01-17 07:50

Thanks all for the help - turns out it was a WiX issue.

When the Product ID GUID was left explicit & hardcoded as in the question, the resulting .msi had no ProductCode property but a Product ID property instead when inspected with orca.

Once I changed the GUID to '*' to auto-generate, the ProductCode showed up and all works fine with syntax confirmed by the other answers.

查看更多
登录 后发表回答