共用方式為


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.

Remarks

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

Exceptions

The following conditions may cause an exception:

Tasks

Here 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 Name to "Author's Name" in the key HKEY_CURRENT_USER\Software\MyApp.

Dim readValue As Object
readValue = My.Computer.Registry.GetValue _
("HKEY_CURRENT_USER\Software\MyApp", "Name", Nothing)

Requirements

Namespace: Microsoft.VisualBasic.MyServices

Class: RegistryProxy (provides access to Registry)

Assembly: Visual Basic Runtime Library (in Microsoft.VisualBasic.dll)

Permissions

No permissions are required.

See Also

Tasks

Troubleshooting: Manipulating the Registry

Reference

My.Computer.Registry Object
Microsoft.Win32.RegistryValueKind
Microsoft.Win32.Registry.SetValue

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