Why does RegistryKey.OpenSubKey("blah", false) allow writes?

  • Thread starter Thread starter akash
  • Start date Start date
A

akash

I have code that accidently opens a registry key using
RegistryKey.OpenSubKey("blah", false) instead of
RegistryKey.OpenSubKey("blah", true) even though it requires writable
access.

However, I never spotted this error until recently because my app can
still write to this key on most machines! Is there some other level of
security that is overriding the behaviour specified in the code?

Thanks
Akash
 
Hello, akash!

RegistryKey.OpenSubKey("blah", false)
this call means that you don't want to write to the registry subkey, that is why the code doesn't perform write check

RegistryKey.OpenSubKey("blah", true)
this call does the same thing as the upper one, but check also if the application _can_ write to the registry.

That is if your app is working under account that is not allowed to write to registry then RegistryKey.OpenSubKey("blah", true) - will fail.

RegistryKey.OpenSubKey("blah", false) - will not fail, however, when you will try to write you'll get an exception.
--
Regards, Vadym Stetsyak
www: http://vadmyst.blogspot.com
 
Back
Top