安装程序自定义操作问题 – 无法写入注册表项
在自定义操作编辑器中,我已将自定义操作添加到该过程的安装和卸载阶段。 在属性窗口中,我将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);
- .NET – UserControl拖放 – 子控件
- 在WebApi服务中validationAzure移动服务令牌
- Enum.HasFlag,为什么没有Enum.SetFlag?
- 过滤掉Type.GetMethods()返回的自动生成的方法(getter / setter / add / remove / .etc)
- 在c#中是否有类似于Application_Start的类库
- Process.Start在某些客户端上随机阻塞/挂起
- 使用Linq对象,如何轻松地创建的空字典?
- 如何只保留DateTime的日期部分,同时保留时间部分?
- Web API中DefaultControllerFactory的等价物是什么?