O'Reilly logo

C# in a Nutshell by Peter Drayton, Ted Neward, Ben Albahari

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Name

RegistryKey

Synopsis

The RegistryKey class contains the core functionality for reading and writing to the Windows registry. Each RegistryKey object represents an individual key in the registry. You can use the properties of this class to find out how many values this key contains (ValueCount), how many subkeys (SubKeyCount) there are, and the fully qualified key name (Name).

To open a subkey for modification, use the overloaded version of the OpenSubKey() method — which allows you to specify the writable parameter — and set it to true. You can open subkeys that are several levels deep by separating keys with a backslash (\). In C#, the backslash must be escaped, as in mykey.OpenKey("Software\\Microsoft"). You can also use methods such as CreateSubKey() and DeleteSubKey(). In the registry, keys are logical groupings, and values are the entries used to store the actual data. You can use the GetValue(), SetValue(), and DeleteValue() methods to manipulate a named value in the current key.

Changes to the registry are propagated across the system automatically, and are flushed to disk automatically by the system. You should never need to use methods such as Flush(), unless you require absolute certainty that a registry change has been written to disk. The OpenRemoteBaseKey() method opens the registry on a remote computer, provided both machines are running the remote registry service and have remote administration enabled.

public sealed class RegistryKey : MarshalByRefObject : IDisposable ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required