SetValue Method


SetValue Method

Location

My.Computer.Registry.SetValue

Syntax

     My.Computer.Registry.SetValue(keyName, valueName, value _    [, valueKind]) 


keyName (required; String)

The hierarchy key under which to write the data for a value.


valueName (required; Object)

The name of the value to be added or updated. To set the default value (the "(Default)" entry) for a particular key, use Nothing or an empty string for this parameter.


value (required; Object)

The data to be written to the new or existing value. This parameter cannot be set to Nothing.


valueKind (optional; RegistryValueKind enumeration)

The type of data to be written. One of the following Microsoft.Win32.RegistryValueKind enumeration values.

Value

Description

Binary

Binary data.

DWord

A 32-bit "double word" numeric value.

ExpandString

A null-terminated path string with embedded environment variables. Surround such environment variables with matching percent signs (like "%PATH%"). All embedded environment variables are expanded to their current settings when this registry value is read later.

MultiString

An array of strings. Each string is followed by a null character, and the full value is terminated by two null characters.

QWord

A 64-bit "quad word" numeric value.

String

A null-terminated string.

Unknown

Lets the SetValue method determine the correct storage method automatically.


Description

The SetValue method writes or updates a new or existing data value within a registry key location.

Usage at a Glance

  • If the specified key or value does not exist, it is created. This includes any middle-level entries in the hierarchy leading to the key. For instance, if you specify "HKEY_CURRENT_USER\Level1\Level2" and neither Level1 nor Level2 exist, they will both be created.

  • keyName must start with the name of a valid registry hive, such as HKEY_CURRENT_USER.

  • To clear a registry value (but not delete it), send an empty version of its data type. For instance, to clear a string value, send an empty string (""). The value parameter cannot be set to Nothing.

  • You must have sufficient security permissions to read or write keys and values in the registry.

  • Avoid setting valueKind to Unknown when possible, as it reduces your application's control over its own stored data.

Example

The following code updates a string in the registry.

     ' ----- Store the screen position for next time.     My.Computer.Registry.SetValue( _        "HKEY_CURRENT_USER\Software\MyCompany\MySoftware", _        "ScreenPosition", Me.Left & "," & Me.Top, _        Microsoft.Win32.RegistryValueKind.String) 

Related Framework Entries

  • Microsoft.VisualBasic.MyServices.RegistryProxy.SetValue Method

  • Microsoft.Win32.RegistryKey.SetValue Method

See Also

ClassesRoot Property, CurrentConfig Property, CurrentUser Property, DynData Property, GetValue Method, LocalMachine Property, PerformanceData Property, Registry Object, Users Property




Visual Basic 2005(c) In a Nutshell
Visual Basic 2005 in a Nutshell (In a Nutshell (OReilly))
ISBN: 059610152X
EAN: 2147483647
Year: 2004
Pages: 712

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net