| The script below demonstrates the write,
| |
| | For Each strValue In arrValues
|
| read and deletion for each type of value
| |
| | Wscript.Echo strValueName & " = " &
|
| in the Windows registry.
| |
| | strValue
|
| The registry value types are:
| |
| | Next
|
| - String (REG_SZ): A fixed-length text
| |
| | 'Delete Binary valuestrKeyPath =
|
| string.
| |
| | "Registry Test"strValueName = "Binary
|
| - Binary (REG_BINARY): Raw binary data.
| |
| | Test"objRegistry.DeleteValue
|
| Most hardware component information is
| |
| | HKEY_CURRENT_USER,strKeyPath,strValueName
|
| stored as binary data and is displayed in
| |
| | 'Set DWORD valuestrKeyPath = "Registry
|
| Registry Editor in hexadecimal format.
| |
| | Test"strValueName = "DWORD Test"intValue
|
| - DWORD (REG_DWORD): Data represented by
| |
| | = 123objRegistry.SetDWORDValue
|
| a number that is 4 bytes long (a 32-bit
| |
| | HKEY_CURRENT_USER,strKeyPath,strValueName
|
| integer). Many parameters for device
| |
| | ,intValue
|
| drivers and services are this type and
| |
| | 'Get DWORD valuestrKeyPath = "Registry
|
| are displayed in Registry Editor in
| |
| | Test"strValueName = "DWORD
|
| binary, hexadecimal, or decimal format.
| |
| | Test"objRegistry.GetDWORDValue
|
| - Multi-String (REG_MULTI_SZ): A multiple
| |
| | HKEY_CURRENT_USER,strKeyPath,strValueName
|
| string. Values that contain lists or
| |
| | ,intValue
|
| multiple values in a form that people can
| |
| | Wscript.Echo strValueName & " = " &
|
| read are generally this type. Entries are
| |
| | intValue
|
| separated by spaces, commas, or other
| |
| | 'Delete DWORD valuestrKeyPath = "Registry
|
| marks.
| |
| | Test"strValueName = "DWORD
|
| - Expandable String (REG_EXPAND_SZ): A
| |
| | Test"objRegistry.DeleteValue
|
| variable-length data string. This data
| |
| | HKEY_CURRENT_USER,strKeyPath,strValueName
|
| type includes variables that are resolved
| |
| | 'Set Multi-String valuestrKeyPath =
|
| when a program or service uses the data.
| |
| | "Registry Test"strValueName =
|
| Option Explicit
| |
| | "Multi-String Test"arrValues =
|
| Const HKEY_CLASSES_ROOT = &H80000000
| |
| | Array("Test1","Test2","Test3")objRegistry
|
| Const HKEY_CURRENT_USER = &H80000001
| |
| | .SetMultiStringValue
|
| Const HKEY_LOCAL_MACHINE = &H80000002
| |
| | HKEY_CURRENT_USER,strKeyPath,strValueName
|
| Const HKEY_USERS = &H80000003
| |
| | ,arrValues
|
| Const HKEY_CURRENT_CONFIG = &H80000005
| |
| | 'Get Multi-String valuestrKeyPath =
|
| Dim strComputer
| |
| | "Registry Test"strValueName =
|
| Dim objRegistry
| |
| | "Multi-String
|
| Dim strKeyPath
| |
| | Test"objRegistry.GetMultiStringValue
|
| Dim strValueName
| |
| | HKEY_CURRENT_USER,strKeyPath,strValueName
|
| Dim strValue
| |
| | ,arrValues
|
| Dim arrValues
| |
| | For Each strValue In arrValues
|
| Dim intValuestrComputer = "."
| |
| | Wscript.Echo strValueName & " = " &
|
| Set
| |
| | strValue
|
| objRegistry=GetObject("winmgmts:{imperson
| |
| | Next
|
| ationLevel=impersonate}!" & strComputer &
| |
| | 'Delete Multi-String valuestrKeyPath =
|
| "rootdefault:StdRegProv")
| |
| | "Registry Test"strValueName =
|
| 'Create KeystrKeyPath = "Registry
| |
| | "Multi-String
|
| Test"objRegistry.CreateKey
| |
| | Test"objRegistry.DeleteValue
|
| HKEY_CURRENT_USER,strKeyPath
| |
| | HKEY_CURRENT_USER,strKeyPath,strValueName
|
| 'Set String valuestrKeyPath = "Registry
| |
| | 'Set Expandable String valuestrKeyPath =
|
| Test"strValueName = "String Test"strValue
| |
| | "Registry Test"strValueName = "Expandable
|
| = "123"objRegistry.SetStringValue
| |
| | String Test"strValue =
|
| HKEY_CURRENT_USER,strKeyPath,strValueName
| |
| | "123"objRegistry.SetExpandedStringValue
|
| ,strValue
| |
| | HKEY_CURRENT_USER,strKeyPath,strValueName
|
| 'Get String valuestrKeyPath = "Registry
| |
| | ,strValue
|
| Test"strValueName = "String
| |
| | 'Get Expandable String valuestrKeyPath =
|
| Test"objRegistry.GetStringValue
| |
| | "Registry Test"strValueName = "Expandable
|
| HKEY_CURRENT_USER,strKeyPath,strValueName
| |
| | String
|
| ,strValue
| |
| | Test"objRegistry.GetExpandedStringValue
|
| Wscript.Echo strValueName & " = " &
| |
| | HKEY_CURRENT_USER,strKeyPath,strValueName
|
| strValue
| |
| | ,strValue
|
| 'Delete String valuestrKeyPath =
| |
| | Wscript.Echo strValueName & " = " &
|
| "Registry Test"strValueName = "String
| |
| | strValue
|
| Test"objRegistry.DeleteValue
| |
| | 'Delete Expandable String valuestrKeyPath
|
| HKEY_CURRENT_USER,strKeyPath,strValueName
| |
| | = "Registry Test"strValueName =
|
| 'Set Binary valuestrKeyPath = "Registry
| |
| | "Expandable String
|
| Test"strValueName = "Binary
| |
| | Test"objRegistry.DeleteValue
|
| Test"arrValues =
| |
| | HKEY_CURRENT_USER,strKeyPath,strValueName
|
| Array(1,2,3,4,5,6,7,8,9,10)objRegistry.Se
| |
| | 'Delete KeystrKeyPath = "Registry
|
| tBinaryValue
| |
| | Test"objRegistry.DeleteKey
|
| HKEY_CURRENT_USER,strKeyPath,strValueName
| |
| | HKEY_CURRENT_USER,strKeyPath
|
| ,arrValues
| |
| | Set objRegistry = Nothing
|
| 'Get Binary valuestrKeyPath = "Registry
| |
| | Please note:
|
| Test"strValueName = "Binary
| |
| | The above script write, read and delete
|
| Test"objRegistry.GetBinaryValue
| |
| | values in the HKCU hive but can easily be
|
| HKEY_CURRENT_USER,strKeyPath,strValueName
| |
| | modified to write to any of the registry
|
| ,arrValues
| |
| | hives.
|