質問

アプリケーションをアンインストールするとき、 Wix の設定をすべて削除して、 元のインストール後に追加されたファイル。アンインストーラーは、MSIファイルから最初にインストールされたディレクトリとファイルのみを削除し、後でアプリケーションフォルダーに追加された他のすべてを残すようです。言い換えれば、アンインストール時にディレクトリを削除したいのです。どうすればいいですか?

役に立ちましたか?

解決

RemoveFile要素とOn =" アンインストール"。以下に例を示します。

<Directory Id="CommonAppDataFolder" Name="CommonAppDataFolder">
  <Directory Id="MyAppFolder" Name="My">
    <Component Id="MyAppFolder" Guid="*">
      <CreateFolder />
      <RemoveFile Id="PurgeAppFolder" Name="*.*" On="uninstall" />
    </Component>
  </Directory>
</Directory>

更新

  

100%機能しませんでした。ファイルは削除されましたが、追加のディレクトリはありません-   インストール後に作成されたものは削除されました。それについて何か考えはありますか? – pribeiro

残念ながら、Windowsインストーラーはサブディレクトリのあるディレクトリの削除をサポートしていません。この場合、カスタムアクションに頼らなければなりません。または、サブフォルダーとは何かを知っている場合は、RemoveFolder要素とRemoveFile要素の束を作成します。

他のヒント

RemoveFolderEx WiXのUtil拡張の要素。
このアプローチでは、すべてのサブディレクトリも削除されます(
RemoveFile 要素を直接使用するとは対照的) 。この要素は、MSIデータベースの RemoveFile および RemoveFolder テーブルに一時行を追加します。

これを行うには、アンインストール時に呼び出されるカスタムアクションを作成しました。

WiXコードは次のようになります。

<Binary Id="InstallUtil" src="InstallUtilLib.dll" />

<CustomAction Id="DIRCA_TARGETDIR" Return="check" Execute="firstSequence" Property="TARGETDIR" Value="[ProgramFilesFolder][Manufacturer]\[ProductName]" />
<CustomAction Id="Uninstall" BinaryKey="InstallUtil" DllEntry="ManagedInstall" Execute="deferred" />
<CustomAction Id="UninstallSetProp" Property="Uninstall" Value="/installtype=notransaction /action=uninstall /LogFile= /targetDir=&quot;[TARGETDIR]\Bin&quot; &quot;[#InstallerCustomActionsDLL]&quot; &quot;[#InstallerCustomActionsDLLCONFIG]&quot;" />

<Directory Id="BinFolder" Name="Bin" >
    <Component Id="InstallerCustomActions" Guid="*">
        <File Id="InstallerCustomActionsDLL" Name="SetupCA.dll" LongName="InstallerCustomActions.dll" src="InstallerCustomActions.dll" Vital="yes" KeyPath="yes" DiskId="1" Compressed="no" />
        <File Id="InstallerCustomActionsDLLCONFIG" Name="SetupCA.con" LongName="InstallerCustomActions.dll.Config" src="InstallerCustomActions.dll.Config" Vital="yes" DiskId="1" />
    </Component>
</Directory>

<Feature Id="Complete" Level="1" ConfigurableDirectory="TARGETDIR">
    <ComponentRef Id="InstallerCustomActions" />
</Feature>

<InstallExecuteSequence>
    <Custom Action="UninstallSetProp" After="MsiUnpublishAssemblies">$InstallerCustomActions=2</Custom>
    <Custom Action="Uninstall" After="UninstallSetProp">$InstallerCustomActions=2</Custom>
</InstallExecuteSequence>

InstallerCustomActions.DLLのOnBeforeUninstallメソッドのコードは(VBで)このようになります。

Protected Overrides Sub OnBeforeUninstall(ByVal savedState As System.Collections.IDictionary)
    MyBase.OnBeforeUninstall(savedState)

    Try
        Dim CommonAppData As String = Me.Context.Parameters("CommonAppData")
        If CommonAppData.StartsWith("\") And Not CommonAppData.StartsWith("\\") Then
            CommonAppData = "\" + CommonAppData
        End If
        Dim targetDir As String = Me.Context.Parameters("targetDir")
        If targetDir.StartsWith("\") And Not targetDir.StartsWith("\\") Then
            targetDir = "\" + targetDir
        End If

        DeleteFile("<filename.extension>", targetDir) 'delete from bin directory
        DeleteDirectory("*.*", "<DirectoryName>") 'delete any extra directories created by program
    Catch
    End Try
End Sub

Private Sub DeleteFile(ByVal searchPattern As String, ByVal deleteDir As String)
    Try
        For Each fileName As String In Directory.GetFiles(deleteDir, searchPattern)
            File.Delete(fileName)
        Next
    Catch
    End Try
End Sub

Private Sub DeleteDirectory(ByVal searchPattern As String, ByVal deleteDir As String)
    Try
        For Each dirName As String In Directory.GetDirectories(deleteDir, searchPattern)
            Directory.Delete(dirName)
        Next
    Catch
    End Try
End Sub

これは@trondaの提案のバリエーションです。ファイル&quot; install.log&quot;を削除していますアンインストール中に別のカスタムアクションによって作成される:

<Product>
    <CustomAction Id="Cleanup_logfile" Directory="INSTALLFOLDER"
    ExeCommand="cmd /C &quot;del install.log&quot;"
    Execute="deferred" Return="ignore" HideTarget="no" Impersonate="no" />

    <InstallExecuteSequence>
      <Custom Action="Cleanup_logfile" Before="RemoveFiles" >
        REMOVE="ALL"
      </Custom>
    </InstallExecuteSequence>
</Product>

理解している限り、「RemoveFile」を使用することはできません。このファイルはインストール後に作成され、コンポーネントグループの一部ではないためです。

WIXの専門家ではありませんが、これに対する可能な(簡単な?)ソリューションは WIXの組み込み拡張機能の一部である、Quiet Executionカスタムアクション

/ Sおよび/ Qオプションを指定して rmdir MS DOSコマンドを実行できます。

<Binary Id="CommandPrompt" SourceFile="C:\Windows\System32\cmd.exe" />

そして、ジョブを実行するカスタムアクションは簡単です。

<CustomAction Id="DeleteFolder" BinaryKey="CommandPrompt" 
              ExeCommand='/c rmdir /S /Q "[CommonAppDataFolder]MyAppFolder\PurgeAppFolder"' 
              Execute="immediate" Return="check" />

その後、多くの場所で文書化されているようにInstallExecuteSequenceを変更する必要があります。

更新: このアプローチには問題がありました。代わりにカスタムタスクを作成することになりましたが、これを実行可能なソリューションと見なしていますが、詳細を機能させることはできません。

これは、 @Pavel 提案に対するより完全な回答になります。私にとっては100%動作しています:

<Fragment Id="FolderUninstall">
    <?define RegDir="SYSTEM\ControlSet001\services\[Manufacturer]:[ProductName]"?>
    <?define RegValueName="InstallDir"?>
    <Property Id="INSTALLFOLDER">
        <RegistrySearch Root="HKLM" Key="$(var.RegDir)" Type="raw" 
                  Id="APPLICATIONFOLDER_REGSEARCH" Name="$(var.RegValueName)" />
    </Property>

    <DirectoryRef Id='INSTALLFOLDER'>
        <Component Id="UninstallFolder" Guid="*">
            <CreateFolder Directory="INSTALLFOLDER"/>
            <util:RemoveFolderEx Property="INSTALLFOLDER" On="uninstall"/>
            <RemoveFolder Id="INSTALLFOLDER" On="uninstall"/>
            <RegistryValue Root="HKLM" Key="$(var.RegDir)" Name="$(var.RegValueName)" 
                    Type="string" Value="[INSTALLFOLDER]" KeyPath="yes"/>
        </Component>
    </DirectoryRef>
</Fragment>

そして、Product要素の下:

<Feature Id="Uninstall">
    <ComponentRef Id="UninstallFolder" Primary="yes"/>
</Feature>

この方法では、アンインストール時に削除するフォルダーの目的のパスをレジストリ値に設定します。 最後に、INSTALLFOLDERとレジストリフォルダーの両方がシステムから削除されます。レジストリへのパスは、他のハイブや他の場所にあることに注意してください。

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top