3

Windows インストーラー (wix ではありません) を使用してプログラムのインストーラーを作成しています。場合によっては、カスタム アクションからインストール プロセスをキャンセルしたいことがあります。さらに、テキストにエラーメッセージを表示したい。どうやってこれを行うのですか?

C#、.net 3.5

4

4 に答える 4

3

これを行うには、エラー カスタム アクションを作成します。エラー カスタム アクションの条件を失敗条件に設定し (条件が true と評価された場合、インストールは失敗します)、メッセージをカスタム テキストに設定します。

于 2010-05-11T19:30:06.810 に答える
1

私のために働くこと:

コンテキスト:何らかの理由で、ユーザーに3.5SP1がインストールされているかどうかを確認し、インストールをキャンセルして、インストールされていない場合は正しいダウンロードページにリダイレクトする必要があります。

ステップ1:次のようにインストーラーを変更します

    [System.Security.Permissions.SecurityPermission(System.Security.Permissions.SecurityAction.Demand)]
    public override void Install(IDictionary stateSaver)
    {
        //Check if the FrameWork 3.5SP1 is installed
        if (mycondition)
        {
            //3.5SP1 is installed, ask for framework install
            if (TopMostMessageBox.Show("body", "title", MessageBoxButtons.YesNo) == DialogResult.Yes)
                System.Diagnostics.Process.Start("http://Microsoft FRW Link");

            WindowHandler.Terminate();
        }
        else
            base.Install(stateSaver);
    }

ステップ2:そのコードを使用してMessageBoxをホストします(他の場所に持っていきました。自分で見つける時間はありません)

static public class TopMostMessageBox
{
    static public DialogResult Show(string message)
    {
        return Show(message, string.Empty, MessageBoxButtons.OK);
    }

    static public DialogResult Show(string message, string title)
    {
        return Show(message, title, MessageBoxButtons.OK);
    }

    static public DialogResult Show(string message, string title,
        MessageBoxButtons buttons)
    {
        // Create a host form that is a TopMost window which will be the 

        // parent of the MessageBox.

        Form topmostForm = new Form();
        // We do not want anyone to see this window so position it off the 

        // visible screen and make it as small as possible

        topmostForm.Size = new System.Drawing.Size(1, 1);
        topmostForm.StartPosition = FormStartPosition.Manual;
        System.Drawing.Rectangle rect = SystemInformation.VirtualScreen;
        topmostForm.Location = new System.Drawing.Point(rect.Bottom + 10,
            rect.Right + 10);
        topmostForm.Show();
        // Make this form the active form and make it TopMost

        topmostForm.Focus();
        topmostForm.BringToFront();
        topmostForm.TopMost = true;
        // Finally show the MessageBox with the form just created as its owner

        DialogResult result = MessageBox.Show(topmostForm, message, title,
            buttons);
        topmostForm.Dispose(); // clean it up all the way


        return result;
    }
}

ステップ3:msiexecを強制終了します

internal static class WindowHandler
{
    internal static void Terminate()
    {
        var processes = Process.GetProcessesByName("msiexec").OrderBy(x => x.StartTime); \\DO NOT FORGET THE ORDERBY!!! It makes the msi processes killed in the right order
        foreach (var process in processes)
        {
            var hWnd = process.MainWindowHandle.ToInt32(); 
            ShowWindow(hWnd, 0); //This is to hide the msi window and only show the popup
            try
            {
                process.Kill();
            }
            catch
            {
            }
        }
    }

    [DllImport("User32")]
    private static extern int ShowWindow(int hwnd, int nCmdShow);
}

シェーカーではなくスプーンで混ぜて出してください;)

于 2011-10-12T05:29:05.463 に答える
1

カスタム アクションから ERROR_INSTALL_USEREXIT を返すだけです。

http://msdn.microsoft.com/en-us/library/windows/desktop/aa368072(v=vs.85).aspx

エラーメッセージの表示方法については、次のリンクを参照してください。

http://msdn.microsoft.com/en-us/library/windows/desktop/aa371247(v=vs.85).aspx

于 2011-10-12T06:22:14.600 に答える