Share via


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:

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

RegistryPermission

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

Common Registry Tasks

Security and the Registry

Reading from and Writing to the Registry Using My

Registry Access for Visual Basic 6.0 Users

Reference

My.Computer.Registry Object

Microsoft.Win32.RegistryValueKind

Registry.SetValue