My.Computer.Registry.SetValue Method
Writes a value to a registry key.
' Usage
My.Computer.Registry.SetValue(keyName ,valueName ,value)
My.Computer.Registry.SetValue(keyName ,valueName ,value ,valueKind)
' Declaration
Public Sub SetValue( _
ByVal keyName As String, _
ByVal valueName As String, _
ByVal value As Object _
)
' -or-
Public Sub SetValue( _
ByVal keyName As String, _
ByVal valueName As String, _
ByVal value As Object, _
ByVal valueKind As Microsoft.Win32.RegistryValueKind _
)
Parameters
keyName
String. Name of the key to be written to. Required.valueName
String. Name of the value to be written. Required.value
Object. Value to be written. Required.valueKind
RegistryValueKind. Required.
Remarks
If the specified key or value does not exist, it is created.
Exceptions
The following conditions may cause an exception:
The name of the key is Nothing (ArgumentNullException).
The key name exceeds the 255-character limit (ArgumentException).
The specified hive is not valid (ArgumentException).
The key is closed (IOException).
The path is not valid (IOException).
The registry key is read-only (UnauthorizedAccessException).
Tasks
Following is an example of a task involving the My.Computer.Registry.SetValue method.
To |
See |
---|---|
Set a value in a registry key |
How to: Create a Registry Key and Set Its Values in Visual Basic |
Example
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")
Requirements
Namespace:Microsoft.VisualBasic.MyServices
Class:RegistryProxy (provides access to Registry)
Assembly: Visual Basic Runtime Library (in Microsoft.VisualBasic.dll)
Permissions
The following permission may be required:
Permission |
Description |
---|---|
Controls the ability to access the registry. Associated enumerations: RegistryPermissionAccess.Write, RegistryPermissionAccess.Create. |
For more information, see Code Access Security and Requesting Permissions.
See Also
Tasks
Troubleshooting: Manipulating the Registry
Concepts
Reading from and Writing to the Registry Using My
Registry Access for Visual Basic 6.0 Users