Error 1001. Can't write to register's key

lindabram

New member
Joined
Nov 1, 2012
Messages
1
Programming Experience
Beginner
I have some code in the Custom Actions editor as I need to install & Uninstall steps of certain process. I have also marked the CustomActionData property as :

/TARGETDIR = "[TARGETDIR]"

in the properties window

Hope the above will pass installation directory info in to the custom action.


It seems to be firing, but my problem is, I have received the following error message:

"Error 1001. Can't write to register's key" (or something like that, I'm translating it from my local language).

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);

}

I'm not sure what I did wrong.


Linda
 

JohnH

C# Forum Moderator
Staff member
Joined
Apr 23, 2011
Messages
1,562
Location
Norway
Programming Experience
10+
That version of OpenSubKey opens the key in readonly mode. You don't need that call since CreateSubKey opens existing key or creates new key with write access.
 
Top Bottom