Reputation: 3265
I'm working on a C# project and I'm very confused about the creation of a registry key.
I have a Wix Installer. And the and of the setup File, i'm calling a custom action to create sub key (I'v try with the wix feature but it didn't work).
My custom action is :
RegistryKey Nkey = Registry.LocalMachine;
RegistryKey valkey = Nkey.OpenSubKey(Manager.REGKEY, true); //=> REGKEY = "Software\\MyService"
if (valkey == null)
{
valkey = Nkey.CreateSubKey(GestionCertificats.REGKEY);
}
valkey.Close();
Registry.LocalMachine.CreateSubKey(@"SYSTEM\CurrentControlSet\services\eventlog\Application\MyService");
After install, I can see the second key but no the first one. I'm not sure to right understand the operation of the keys. I'm working on a windows 7 64 bit, I'm compiling with "Any CPU" but my application seems to be in x86.
I've try to debug the action. value valkey
is not null, but I didn't see the key with regedit. By forcing the CreateSubKey
I still have no key.
I don't know what to do, I need help.
Upvotes: 1
Views: 2753
Reputation: 126
just a guess, because everything looks okay.
try closing the key returned. The description of the dispose of a key it clears resources but doesn't say it flushes it.
RegistryKey key = Registry.LocalMachine.CreateSubKey(@"SYSTEM\CurrentControlSet\services\eventlog\Application\MyService");
key.Close();
Upvotes: 1