In the custom action editor, I added custom actions to set and remove process steps. In the properties window, I marked the CustomActionData property as:
/TARGETDIR = "[TARGETDIR]"
I hope the above transmits installation information to a user action.
The custom action seems to fire, but I get the following error message:
"Error 1001. Unable to write registration key" (or something like that, I translated it from my local language).
What am I doing wrong?
using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Configuration.Install;
using System.Linq;
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();
}
}
}
source
share