RegistryProxy.SetValue Method (String, String, Object, RegistryValueKind)

Writes a value to a registry key.

Namespace:  Microsoft.VisualBasic.MyServices
Assembly:  Microsoft.VisualBasic (in Microsoft.VisualBasic.dll)

public void SetValue(
	string keyName,
	string valueName,
	Object value,
	RegistryValueKind valueKind
)

Parameters

keyName
Type: System.String

String. Name of the key to be written to. Required.

valueName
Type: System.String

String. Name of the value to be written. Required.

value
Type: System.Object

Object. Value to be written. Required.

valueKind
Type: Microsoft.Win32.RegistryValueKind

RegistryValueKind. Required.

ExceptionCondition
ArgumentNullException

value is Nothing.

ArgumentException

keyName does not begin with a valid registry root.

-or-

keyName is longer than the maximum length allowed (255 characters).

-or-

The type of value does not match the registry data type specified by valueKind, therefore the data cannot be converted properly.

UnauthorizedAccessException

The RegistryKey is read-only, and thus cannot be written to; for example, it is a root-level node, or it has not been opened with write access.

SecurityException

The user does not have the permissions required to create or modify registry keys.

If the specified key or value does not exist, it is created.

Here is an example of a task involving the My.Computer.Registry.SetValue method.

This example sets the value FontColor to "red" in the key HKEY_LOCAL_MACHINE\Software\MyCompany\Preferences.

My.Computer.Registry.LocalMachine.OpenSubKey(
  "Software\MyCompany\Preferences", True)
My.Computer.Registry.LocalMachine.SetValue("FontColor", "red")

.NET Framework

Supported in: 4.6, 4.5, 4, 3.5, 3.0, 2.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Was this page helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2015 Microsoft