6

カスタム アクション エディターで、カスタム アクションをプロセスのインストール ステージとアンインストール ステージに追加しました。プロパティ ウィンドウで、CustomActionData プロパティを次のようにマークしました。

/TARGETDIR = "[TARGETDIR]"

上記がインストールディレクトリ情報をカスタムアクションに渡すことを願っています。

カスタム アクションが起動しているように見えますが、次のエラー メッセージが表示されます。

「エラー 1001。レジスタのキーに書き込めません」 (またはそのようなもの、ローカル言語から翻訳しています)。

私は何を間違っていますか?

using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Configuration.Install;
using System.Linq;
//using System.Windows.Forms;
using Microsoft.Win32;

namespace CustomActions
{
    [RunInstaller(true)]
    public partial class Installer1 : Installer
    {
        public override void Install(IDictionary stateSaver)
        {
            base.Install(stateSaver);

            const string key_path = "SOFTWARE\\VendorName\\MyAppName";
            const string key_value_name = "InstallationDirectory";

            RegistryKey key = Registry.LocalMachine.OpenSubKey(key_path);

            if (key == null)
            {
                key = Registry.LocalMachine.CreateSubKey(key_path);
            }

            string tgt_dir = Context.Parameters["TARGETDIR"];

            key.SetValue(key_value_name, tgt_dir);

        }

        public override void Uninstall(IDictionary savedState)
        {
            base.Uninstall(savedState);

            const string key_path = "SOFTWARE\\VendorName";
            const string key_name = "MyAppName";

            RegistryKey key = Registry.LocalMachine.OpenSubKey(key_path);

            if (key.OpenSubKey(key_name) != null)
            {
                key.DeleteSubKey(key_name);
            }
        }

        public override void Rollback(IDictionary savedState)
        {
            base.Rollback(savedState);
        }


        public Installer1()
        {
            InitializeComponent();
        }
    }
}
4

1 に答える 1

11

変更してみてください:
RegistryKey key = Registry.LocalMachine.OpenSubKey(key_path);

に:
RegistryKey key = Registry.LocalMachine.OpenSubKey(key_path, Microsoft.Win32.RegistryKeyPermissionCheck.ReadWriteSubTree);

于 2009-11-23T12:06:22.513 に答える