مشكلة الإجراء المخصص للتثبيت - لا يمكن الكتابة لتسجيل المفتاح

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