2017-10-13 174 views
1

我的想法是使用.msi安裝文件創建卸載文件。我閱讀了一些關於在這裏創建卸載程序快捷方式的信息:http://wixtoolset.org/documentation/manual/v3/howtos/files_and_registry/create_uninstall_shortcut.html,但是我無法找到有關在msi構建後製作卸載文件的信息,或許誰知道它是可能的?如果可能的話我該怎麼做呢?或者也許有可能做的CMD腳本?只需編寫腳本即可自動從mashine中卸載我的程序。我的代碼是:Wix創建無聲卸載文件

<?xml version="1.0" encoding="UTF-8"?> 
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi" xmlns:util="http://schemas.microsoft.com/wix/UtilExtension"><?define WpfApp1_TargetDir=$(var.WpfApp1.TargetDir)?> 
    <Product Id="*" Name="SetupProject2" Language="1033" Version="1.0.0.0" Manufacturer="Andrejka" UpgradeCode="PUT-GUID-HERE"> 
     <Package InstallerVersion="200" Compressed="yes" InstallScope="perMachine" /> 

    <Property Id="WIXUI_INSTALLDIR" Value="TESTFILEPRODUCTDIR" /> 
    <Property Id="WixShellExecTarget" Value="[#WpfApp1.exe]" /> 
    <CustomAction Id="LaunchApplication" BinaryKey="WixCA" DllEntry="WixShellExec" Impersonate="yes" /> 
    <Property Id="LAUNCH_APP_ON_EXIT" Value="1" /> 

    <InstallExecuteSequence> 
    <Custom Action='LaunchApplication' After='InstallFiles'/> 
    </InstallExecuteSequence> 
    <Property Id="WIXUI_EXITDIALOGOPTIONALCHECKBOX" Value="1" /> 

     <MajorUpgrade DowngradeErrorMessage="A newer version of [ProductName] is already installed." /> 
     <MediaTemplate EmbedCab="yes"/> 
     <Feature Id="ProductFeature" Title="SetupProject2" Level="1"> 
      <ComponentGroupRef Id="ProductComponents" /> 
     </Feature> 
    </Product> 

    <Fragment> 
     <Directory Id="TARGETDIR" Name="SourceDir"> 
     <Directory Id="TESTFILEPRODUCTDIR" Name="SetupProject2"> 
      <Directory Id="ProgramFilesFolder"> 
       <Directory Id="INSTALLFOLDER" Name="SetupProject2" />  
     </Directory> 
      </Directory> 
     </Directory> 
    </Fragment> 

    <Fragment> 
     <ComponentGroup Id="ProductComponents" Directory="INSTALLFOLDER"> 
      <!-- TODO: Remove the comments around this Component element and the ComponentRef below in order to add resources to this installer. --> 
      <!-- <Component Id="ProductComponent"> --> 
       <!-- TODO: Insert files, registry keys, and other resources here. --> 
      <!-- </Component> --> 

      <Component Id="WpfApp1.exe" Guid="*"> 
       <File Id="WpfApp1.exe" Name="WpfApp1.exe" Source="$(var.WpfApp1_TargetDir)WpfApp1.exe" />  
      </Component> 
      <Component Id="WpfApp1.exe.config" Guid="*"> 
       <File Id="WpfApp1.exe.config" Name="WpfApp1.exe.config" Source="$(var.WpfApp1_TargetDir)WpfApp1.exe.config" /> 
      </Component> 
      <Component Id="aws_sdk_net_core_support.dll" Guid="*"> 
       <File Id="aws_sdk_net_core_support.dll" Name="aws-sdk-net-core-support.dll" Source="$(var.WpfApp1_TargetDir)aws-sdk-net-core-support.dll" /> 
      </Component> 
      <Component Id="AWSSDK.Core.dll" Guid="*"> 
       <File Id="AWSSDK.Core.dll" Name="AWSSDK.Core.dll" Source="$(var.WpfApp1_TargetDir)AWSSDK.Core.dll" /> 
      </Component> 
      <Component Id="AWSSDK.SimpleNotificationService.dll" Guid="*"> 
       <File Id="AWSSDK.SimpleNotificationService.dll" Name="AWSSDK.SimpleNotificationService.dll" Source="$(var.WpfApp1_TargetDir)AWSSDK.SimpleNotificationService.dll" /> 
      </Component> 
      <Component Id="MimeSharp.dll" Guid="*"> 
       <File Id="MimeSharp.dll" Name="MimeSharp.dll" Source="$(var.WpfApp1_TargetDir)MimeSharp.dll" /> 
      </Component> 
     </ComponentGroup> 
    </Fragment> 
</Wix> 
+0

歡迎來到stackoverflow - 我花了一段時間來理解你的問題,但我很高興你似乎得到了你需要的東西。請不要在源中發佈GUID,人們可以複製它們,然後它們不再是唯一的(這會破壞GUID的全部目的)。這非常重要。如果您還沒有生活,我會生成新的組件GUID,或者更好的是,使用將它們設置爲*的概念,它將自動計算組件GUID **。您也可以[**簡化您的WiX源代碼**](https://stackoverflow.com/questions/24732761/syntax-for-guids-in-wix/24769965#24769965)。 –

+0

我在這裏,感謝您的回答 – Andrej

+0

安裝程序和卸載程序是msiexec(Windows安裝程序)。 msi文件是一個數據庫,爲此,WiX是一個可用於構建它的工具。 –

回答

0

一般來說,你不應該把卸載快捷方式在開始菜單中,它實際上是侵犯了微軟的Windows應用程序,我相信徽標要求。相反,您應該讓人們通過添加/刪除程序小程序以正常方式卸載您的產品。

更新:我發現這個答案對這個話題的一些詳細信息:Shortcuts with name "Uninstall <Program Name>" are not displayed in Windows 8/8.1/10

而且,只是所以很顯然,卸載,是一個內置的MSI文件的功能 - 它總是自動提供除非主動阻止(例如某些應用程序隱藏自己不能在添加/刪除程序中顯示)。您的WiX資源中無需額外支付任何額外費用即可支持正確卸載。只需按照Windows Installer指南進行操作即可免費獲得。

如果你問的是一個方法來創建一個卸載批處理文件,然後你可以找到方法來卸載MSI文件在這個「卸載參考」過多:Uninstalling an MSI file from the command line without using msiexec

簡而言之,如果您有MSI的產品代碼,您只需運行下面的命令行卸載您的MSI(您可以通過查詢您的系統找到您的產品代碼:How can I find the product GUID of an installed MSI setup? - 您可能需要查看它自動生成你的產品代碼):

msiexec.exe /x {your-product-guid} 

或只是參照原來的MSI安裝文件這樣的卸載:

msiexec.exe /x "c:\filename.msi 

見上文(卸載參考鏈接的答案)的多很多有關此信息。