Before we create a VBScript to modify the Vista
registry, it is wise to at least consider the alternatives. For example, would a group policy be a better way of achieving our goal? Is it possible to achieve your aim with a .Reg file? You
could even create a logon script containing the command: regedit /s xyz.reg
At the very least, let us have a walk-though with regedit; we want to make sure we are scripting in the correct area of the
registry. A walk-through will also prove that the change we are contemplating will have the desired effect.
Much as I love VBScript, my lingering concern is that if you don't know what you
are doing, then you could destroy your registry, the worst case scenario is you would need a complete re-install of the operating sytem.
Topics
for Modifying the Vista Registry with VBScript.
If you wish to control the Vista registry with VBScript, then .RegWrite is the most important and versatile
method. The simplest task for .RegWrite is to adjust data. For example, suppose you want to display the Build Number on the Vista desktop. You need .RegWrite to change the DWORD value for PaintDesktopVersion from zero, meaning off, to 1, meaning on.
.RegWrite is powerful because not only will it adjust data in the registry's leaf objects, but also it will create new twigs, or even new branches, of the registry. In practical terms, what I mean is if
a value called PaintDesktopVersion did not exist, then .RegWrite could create it, all you have to do is specify the data type. For example: .RegWrite(HKEY_CURRENT_USER\Control Panel\Desktop\PaintDesktopVersion,"00000001", "REG_DWORD").
To take it a stage further .RegWrite would create PainDesktopVersion's parent folder, Desktop, if it did not exist.
VBScript basics
We are overdue for a review of VBScript's basic points.
To begin with, we need is to create an object, let us name it objShell. This is the command to create our object: Set objShell =
CreateObject("WScript.Shell").
Once we have created objShell, then we can employ one of its many methods. In VBScript such methods are preceded with a dot. On this page, we will consider just three methods for modifying the registry, .RegWrite, .RegRead and .RegDelete.
However, in other contexts VBScripts can employ
different methods, such as .Run to launch programs.
Instructions to create your VBScript
Copy and paste the script below into notepad. Alternatively, get your free trial of OnScript.
Save the file with .vbs extension e.g. Build.vbs
Double click your VBScript, then 'OK' the message box.
To help you understand what is happening in the registry, I recommend that you launch regedit and navigate to the section specified by strRoot.
To observe the registry change, simply logoff and logon again. You should now see
.RegWrite Example
' Build.vbs ' Example VBScript to display the Build Number on the desktop. ' Author Guy Thomas http: //computerperformance.co.uk ' Version 1.2 - March 2007 '
---------------------------------------------------------------' ' Option Explicit Dim objShell, strRoot, strModify, strDelete strRoot = "HKEY_CURRENT_USER\Control Panel\Desktop\PaintDesktopVersion"
' Create the Shell object Set objShell = CreateObject("WScript.Shell") strModify = objShell.RegWrite(strRoot,"00000001", "REG_DWORD") WScript.Echo "Error No: " & err.number & " check " & strRoot
strModify = null WScript.Quit
' End of .RegWrite example script.
Guy Recommends: SolarWinds Engineer's Toolset v10
The Engineer's Toolset v10 provides a
comprehensive console of utilities for troubleshooting computer problems. Guy says
it helps me monitor what's occurring on the network, and the tools
teaches me more about how the system literally operates.
There are so many good gadgets, it's like having free rein of a
sweetshop. Thankfully the utilities are displayed logically: monitoring, discovery, diagnostic, and Cisco tools.
Download your copy of the Engineer's Toolset v 10
I don't use .RegRead much. What this method does is extract the string value or dword value from a registry setting. What I find limiting
is that .RegRead only examines the leaf value. Let me amplify what I mean with an example, let us study this location: HKEY_CURRENT_USER\Control Panel\Desktop\PaintDesktopVersion:dword
=00000001.
With .RegRead you can read only the very end value, in this case, 1. My frustration is there is no way of reading PaintDesktopVersion.
Possible uses of .RegRead
What you could do is read a value from the registry, then depending on the result, modify values in
another area of the registry. For example, if UserName = "Fred", then disable the UAC. You could do this via the registry setting ConsentPromptBehavior. Still, there is a better way of
disabling the User Account Control for Fred, that would be by implementing a group policy. It is precisely this situation where I would recommend that before using VBScript, see if there is another method.
And this is advice from someone who loves VBScript.
.RegRead Example 1
' BuildRead.vbs ' Example VBScript to read the value of PaintDesktopVersion. ' Author Guy Thomas http: //computerperformance.co.uk ' Version 1.2 - March 2007 '
---------------------------------------------------------------' ' Option Explicit Dim objShell, strRoot, strModify strRoot = "HKEY_CURRENT_USER\Control Panel\Desktop\PaintDesktopVersion" '
Create the Shell object Set objShell = CreateObject("WScript.Shell") strModify = objShell.RegRead(strRoot) WScript.Echo "Value of PaintDesktopVersion is: " & strModify strModify = null
WScript.Quit
' End of .RegRead example script.
.RegRead Example 2
Here is an example with primitive 'If' Logic.
' BuildRead.vbs ' Example VBScript to read the value of PaintDesktopVersion. ' Author Guy Thomas http: //computerperformance.co.uk ' Version 1.3 - March 2007 '
---------------------------------------------------------------' ' Option Explicit Dim objShell, strRoot, strModify, strBuild strRoot = "HKEY_CURRENT_USER\Control Panel\Desktop\PaintDesktopVersion"
' Create the Shell object Set objShell = CreateObject("WScript.Shell") strModify = objShell.RegRead(strRoot) If strModify = "1" then strBuild = " This means enabled"
Else strBuild =" no build number" End If WScript.Echo "Value of PaintDesktopVersion is: " & strModify & strBuild strModify = null WScript.Quit
' End of .RegRead example script.
Guy Recommends: SolarWinds LANSurveyor
LANSurveyor will produce a neat diagram of your network topology. But that's
just the start;
LANSurveyor can
create an inventory of the hardware and software
of your machines and network devices. Other neat features include dynamic
update for when you add new devices to your network. I also love the ability to export
the diagrams
to Microsoft Visio.
Finally, Guy bets that if you take a free trial of LANSurveyor then you will
find a device on your network that you had forgotten about, or someone else
installed without you realizing!
Before you even think about using .RegDelete, brush-up your VBScript skills. Then focus on the .RegDelete syntax. In particular, pay
close attention to any trailing slash \Desktop\. Beware if you don't understand the significance of the last backslash, you could delete a whole branch of your registry with catastrophic results. For example, if this is where you
are working: HKEY_CURRENT_USER\Control Panel\Desktop\PaintDesktopVersion
A command to delete: HKEY_CURRENT_USER\Control Panel\Desktop\PaintDesktopVersion will just delete one value
PaintDesktopVersion. Observe, no trailing \.
However a command to delete HKEY_CURRENT_USER\Control Panel\Desktop\ will delete all the values in the Desktop folder. Note the final slash,
Desktop\.
Worse, a command to delete HKEY_CURRENT_USER\Control Panel\ would delete a whole branch of the registry.
Deleting HKEY_CURRENT_USER\ does not bear thinking about.
Perhaps
you can now see why you should, take precautions before you experiment with .RegDelete. What you can do is backup the registry via a backup of the system state. You could also export the particular
branch that's the focus of your experiment.
As a matter of learning technique, I also strongly recommend that you start by creating a test registry folder, and master deleting that before you
practice on a live registry folder and its values. Another obvious precaution is to backup the registry, or at the very least, Export that particular branch.
.RegDelete Example 1
Firstly, let us create a new registry folder called AGuy. Then we will add a DWORD called Computer Performance.
Once we have done that, we can check it, and then use example 2 (see below) to delete this registry entry.
' CreateAGuy.vbs ' Example VBScript to create registry settings. ' Author Guy Thomas http: //computerperformance.co.uk ' Version 1.4 - March 2007 '
---------------------------------------------------------------' ' Option Explicit Dim objShell, strRoot, strModify, strDelete strRoot = "HKEY_CURRENT_USER\Control Panel\AGuy\ComputerPerformance"
' Create the Shell object Set objShell = CreateObject("WScript.Shell") strModify = objShell.RegWrite(strRoot,"00000001", "REG_DWORD") WScript.Echo "Check " & strRoot strModify = null WScript.Quit
' End of .RegWrite example script.
.RegDelete Example 2 - The actual deletion
' Delete AGuy.vbs ' Example VBScript to delete a registry entry. ' Author Guy Thomas http: //computerperformance.co.uk ' Version 1.5 - March 2007 '
---------------------------------------------------------------' ' Option Explicit Dim objShell, strRoot, strModify, strDelete strRoot = "HKEY_CURRENT_USER\Control Panel\AGuy\" ' Create the
Shell object Set objShell = CreateObject("WScript.Shell") strModify = objShell.RegDelete(strRoot) WScript.Echo "Check " & strRoot strModify = null WScript.Quit
' End of .RegDelete example
script.
There are a number of commands that we could use to achieve our goal. We could assign the following values the variable strRoot:
HKEY_CURRENT_USER\Control Panel\AGuy\
(Note the backslash)
Because I love VBScript, I felt it only fair to stress that your registry
task really is a job for VBScript. For example is there a group policy to achieve your aim? Another alternative would be merging a .Reg file into your registry. If you are sure that this is indeed a job for a
VBScript, then take the time to familiarise yourself with the syntax of the .RegWrite, .RegRead and especially, .RegDelete.
Windows Vista Training
Train
Signal have an excellent
Windows Vista Training Course. As an MCT
trainer, I am a huge advocate of Train Signal’s products. What impresses is me is that they demonstrate everything that they teach and they stay away from traditional 'lecture-style' training. If
you are looking for a complete DETAILED coverage of Windows Vista, then I highly recommend that you give this course a try. I have reviewed their 18 hours of videos myself, and I guarantee that you will
not be disappointed!
This ebook will explain the workings of the registry. I thoroughly enjoy tweaking the registry, and I want to distill the best of my experiences and pass them on to you.
Each registry tweak has two aims; to solve a specific problem, and to provide general learning points, which help you to master regedit.
Over 60 pages ebook and PDF format
*
Guy
Recommends: Orion's NPM - Network Performance Monitor
Orion's performance monitor is designed for detecting network outages.
A network-centric
view make it easy to see what's working, and what needs your attention.
This utility guides you through troubleshooting by indicating whether the
root cause is faulty equipment or resource overload.