インストーラのカスタムアクションの問題 - キーを登録するに書き込むことはできません

StackOverflow https://stackoverflow.com/questions/1782492

質問

私は、プロセスの段階をインストールおよびアンインストールするカスタムアクションを追加したカスタムアクションエディタで

。プロパティウィンドウで、私のように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();
        }
    }
}
役に立ちましたか?

解決

に変更してみます。
RegistryKey key = Registry.LocalMachine.OpenSubKey(key_path);

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

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