Powered by Blogger.

Wednesday, May 23, 2012

Tag: , ,

Cannot Write to the Registry Key


[UPDATE: this blog was moved to a new one]

Welcome back to my blog!

I've been very busy with some projects that I almost forgot I have a blog :-S
Maybe I will share some stuff in future posts about the WP7 and Windows 8 projects I've been working on.

But for today, just one small tip for writing in the Windows Registry.
RegistryKey windowsRegKey = Registry.LocalMachine.OpenSubKey("pathToTheWantedSubKey");

If you then want to add a sub key, or a value, and write something like this
windowsRegKey Registry.LocalMachine.OpenSubKey("nameOfMyNewSubkey");
you will get an error saying something like "Cannot Write to the Registry Key".

First thing that comes to mind is if the application is running under administrator privileges... this is also needed, but is not the only point. Whenever you open a Registry Subkey use the overloaded method, and pass a true to specify that you will edit it. Something like this:
RegistryKey windowsRegKey = Registry.LocalMachine.OpenSubKey(ShutdownEventTrackerSubkey, true);

Hope it was helpful. As always, feel free to leave any comment, question or suggestion. Thanks for reading!

About Nereo Lopez

Hi, this is Nereo. I've spent my first professional years as .Net Software Engineer, and then moved more into Agile Methodologies. Anyway, I keep playing with all the new technologies that appear, and specially love Hybrid Apps!

0 comentarios:

Post a Comment