Logo
programming4us
programming4us
programming4us
programming4us
Home
programming4us
XP
programming4us
Windows Vista
programming4us
Windows 7
programming4us
Windows Azure
programming4us
Windows Server
programming4us
Windows Phone
 
Windows Vista

Programming the WshShell Object : Working with Registry Entries

- Free product key for windows 10
- Free Product Key for Microsoft office 365
- Malwarebytes Premium 3.7.1 Serial Keys (LifeTime) 2019
3/4/2011 5:43:21 PM
The Registry is one the most crucial data structures in Windows. However, the Registry isn’t a tool that only Windows yields. Most 32-bit applications make use of the Registry as a place to store setup options, customization values the user selected, and much more. Interestingly, your scripts can get in on the act as well. Not only can your scripts read the current value of any Registry setting, but they can also use the Registry as a storage area. This enables you to keep track of user settings, recently used files, and any other configuration data that you’d like to save between sessions. This section shows you how to use the WshShell object to manipulate the Registry from within your scripts.

Reading Settings from the Registry

To read any value from the Registry, use the WshShell object’s RegRead method:

WshShell.RegRead(strName)

WshShellThe WshShell object.
strNameThe name of the Registry value or key that you want to read. If strName ends with a backslash (\), RegRead returns the default value for the key; otherwise, RegRead returns the data stored in the value. Note, too, that strName must begin with one of the following root key names:
 Short NameLong Name
 HKCRHKEY_CLASSES_ROOT
 HKCUHKEY_CURRENT_USER
 HKLMHKEY_LOCAL_MACHINE
 N/AHKEY_USERS
 N/AHKEY_CURRENT_CONFIG

The script in Listing 1 displays the name of the registered owner of this copy of Windows XP.

Listing 1. A Script That Reads the RegisteredOwner Setting from the Registry
Set objWshShell = WScript.CreateObject("WScript.Shell")
strSetting = "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\RegisteredOwner"
strRegisteredUser = objWshShell.RegRead(strSetting)
WScript.Echo strRegisteredUser


Storing Settings in the Registry

To store a setting in the Registry, use the WshShell object’s RegWrite method:

WshShell.RegWrite strName, anyValue [, strType]

WshShellThe WshShell object.
strNameThe name of the Registry value or key that you want to set. If strName ends with a backslash (\), RegWrite sets the default value for the key; otherwise, RegWrite sets the data for the value. strName must begin with one of the root key names detailed in the RegRead method.
anyValueThe value to be stored.
strTypeThe data type of the value, which must be one of the following: REG_SZ (the default), REG_EXPAND_SZ, REG_DWORD, or REG_BINARY.

The following statements create a new key named ScriptSettings in the HKEY_CURRENT_USER root:

Set objWshShell = WScript.CreateObject("WScript.Shell")
objWshShell.RegWrite "HKCU\ScriptSettings\", ""

The following statements create a new value named NumberOfReboots in the HKEY_CURRENT_USER\ScriptSettings key, and set this value to 1:

Set objWshShell = WScript.CreateObject("WScript.Shell")
objWshShell.RegWrite "HKCU\ScriptSettings\NumberOfReboots", 1, "REG_DWORD"

Deleting Settings from the Registry

If you no longer need to track a particular key or value setting, use the RegDelete method to remove the setting from the Registry:

WshShell.RegDelete(strName)

WshShellThe WshShell object.
strNameThe name of the Registry value or key that you want to delete. If strName ends with a backslash (\), RegDeleteRegDelete deletes the value. strName must begin with one of the root key names detailed in the RegRead method. deletes the key; otherwise,

To delete the NumberOfReboots value used in the previous example, you would use the following statements:

Set objWshShell = WScript.CreateObject("WScript.Shell")
objWshShell.RegDelete "HKCU\ScriptSettings\NumberOfReboots"
Other -----------------
- Programming the WshShell Object : Working with Shortcuts
- Programming the WshShell Object : Running Applications
- Programming the WshShell Object : Displaying Information to the User
- Programming the Windows Script Host : Programming the WScript Object
- Programming the Windows Script Host : Programming Objects
- Programming the Windows Script Host : Scripts and Script Execution
- Getting to Know the Windows Vista Registry - Finding Registry Entries
- Getting to Know the Windows Vista Registry - Working with Registry Entries
- Getting to Know the Windows Vista Registry - Keeping the Registry Safe
- Getting to Know the Windows Vista Registry - Understanding the Registry Files
 
 
Top 10
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Finding containers and lists in Visio (part 2) - Wireframes,Legends
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Finding containers and lists in Visio (part 1) - Swimlanes
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Formatting and sizing lists
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Adding shapes to lists
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Sizing containers
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 3) - The Other Properties of a Control
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 2) - The Data Properties of a Control
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 1) - The Format Properties of a Control
- Microsoft Access 2010 : Form Properties and Why Should You Use Them - Working with the Properties Window
- Microsoft Visio 2013 : Using the Organization Chart Wizard with new data
 
programming4us
Windows Vista
programming4us
Windows 7
programming4us
Windows Azure
programming4us
Windows Server