Imports System.ComponentModel Imports System.Configuration.Install Imports System.Windows.Forms Public Class MyInstaller Inherits Installer ''' ''' コンストラクタ ''' Public Sub New() MyBase.New() End Sub ''' ''' アンインストール ''' ''' Public Overrides Sub Uninstall(savedState As IDictionary) MyBase.Uninstall(savedState) ' CustomAction.dllがあるパス取得 Dim path As String = Me.Context.Parameters("assemblypath") ' 親ディレクトリを取得 Dim parentPath As String = System.IO.Path.GetDirectoryName(path) If parentPath.IndexOf("CrimpHelper", StringComparison.OrdinalIgnoreCase) >= 0 Then If System.IO.Directory.Exists(parentPath + "\Data") OrElse System.IO.Directory.Exists(parentPath + "\logs") Then Dim result As DialogResult = MessageBox.Show(parentPath + "フォルダを10秒後に削除します。" + vbCrLf + "先に必要なデータは退避してください。", "削除確認", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2, MessageBoxOptions.DefaultDesktopOnly) If result = DialogResult.Yes Then ' 単純にフォルダ削除するとCustomAction.dllが削除できずにアンインストールエラーとなるため ' バッチファイルをテンポラリフォルダにコピーして実行させる。 Dim tmpPath As String = System.IO.Path.GetTempPath() Const REMOVE_BAT As String = "removeDir.bat" System.IO.File.Copy(parentPath + "\" + REMOVE_BAT, tmpPath + REMOVE_BAT, True) Dim ps As New System.Diagnostics.ProcessStartInfo ps.FileName = "Cmd.exe" ps.Arguments = " /c " + tmpPath + REMOVE_BAT + " " + parentPath ps.WindowStyle = System.Diagnostics.ProcessWindowStyle.Minimized System.Diagnostics.Process.Start(ps) End If End If End If End Sub End Class