Is it possible to read the registry from VS C# 2010 Express? I don't seem to have all of the necessities in the autocomplete selections:

RegistryKey key = Registry.LocalMachine;

I have "using Microsoft.Win32;" imported and what happens is it doesn't seem like the object is created. I've seen examples such as:

RegistryKey key = Registry.LocalMachine;
key = key.OpenSubKey(xxxxxxxx);

I don't get .OpenSubKey options at all. Am I missing something? I'm VERY new to C#, so it would be understandable if I were doing something wrong :)

Thanks!

Recommended Answers

All 2 Replies

Your code should be correct, but you may possibly need to create a new object rather than trying to reuse your key object.

RegistryKey key = Registry.LocalMachine;
var subKey = key.OpenSubKey(location, isWritable); 
// where location is the string of the address for the subkey 
// and isWritable is a bool that specifies whether you are wanting to write to the key (true) or setting it as read-only (false)

EDIT: You may need to create a reference to the Microsoft.Win32 dll in your project. Can you compile your project or does the using statement produce an error?

Your code should be correct, but you may possibly need to create a new object rather than trying to reuse your key object.

RegistryKey key = Registry.LocalMachine;
var subKey = key.OpenSubKey(location, isWritable); 
// where location is the string of the address for the subkey 
// and isWritable is a bool that specifies whether you are wanting to write to the key (true) or setting it as read-only (false)

EDIT: You may need to create a reference to the Microsoft.Win32 dll in your project. Can you compile your project or does the using statement produce an error?

The second line doesn't work in your code. The autocomplete doesn't complete. Once I get to "key.OpenSubKey...", it gives me KeyEventsArg like it doesn't create the key object from the RegistryKey line. I've got a reference to Microsoft.Win32 with the "using Microsoft.Win32" reference. How do I reference a dll in the project other than this reference?

Thanks for the fast response!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.