Reputation: 772
I have used to add registry key
in my windows application
for security purpose. It works great in XP operating System But when I install my Application on Windows 7 OS System(64 Bits) then after 4-5 days my application doesn't find reg key in HKEY_LOCAL_MACHINE\SOFTWARE
.
My Application again asked to add registry key in system. I don't know how my software's reg key is removed or deleted from HKEY_LOCAL_MACHINE\SOFTWARE
in Windows 7 OS 64 bits.
To add reg key in C#.Net App, I used below code:
// Create an instance of HKEY_LOCAL_MACHINE registry key
RegistryKey parentKey = Registry.LocalMachine;
// Open the SOFTWARE registry sub key under the HKEY_LOCAL_MACHINE parent key
RegistryKey softwareKey = parentKey.OpenSubKey("SOFTWARE", true);
// Create a DaveOnC# registry sub key under the SOFTWARE key
RegistryKey subKey = softwareKey.CreateSubKey("MySoftWareRegKey");
subKey.SetValue("Name", encryptedMac, RegistryValueKind.String);
subKey.Close();
softwareKey.Close();
parentKey.Close();
Again I want to mention that no error has been generated in application at running time
, But after some days (may be 4-5 Days) my application couldn't find reg key
in location in Windows 7 64 bit System and forced to me to add it again to execute my application.
So directly my question is how to add Reg Key permanently in Windows 7 OS at HKEY_LOCAL_MACHINE\SOFTWARE
.
Any suggestions or answers are highly appreciate. Thanks in Advance!!!
Upvotes: 0
Views: 436
Reputation: 17618
I suspect this is related to registry virtualisation. Your 32-bit interactive process (registry virtualisation doesn't apply to services or 64-bit processes) probably doesn't have permission to create this registry setting on Windows 7, so the system diverts it to a per-user setting as described in that link. As documented in that link, you can use the Reg.exe command-line utility with the FLAGS option to query the state of the virtualisation flags for any registry key.
I'm not sure why it disappears after a period of time - maybe it's checking under a different user or a different virtualisation policy has been applied? But the real fix is to run the program with admin rights if that's feasible, so that the key can be written properly.
EDIT: In response to your comment, HKEY_LOCAL_MACHINE\Software\Wow6432Node is the 32-bit equivalent of HKEY_LOCAL_MACHINE\Software (although 32-bit applications are not aware of this redirection). So this is normal behaviour for a 32-bit program. What tool are you using to check the registry key - I suspect it's not showing the re-direction?
Upvotes: 1