|
|
Modify the Vista Registry with VBScriptModify the Windows Vista Registry with VBScriptBefore 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: 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..RegWriteIf 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: 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: 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
.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.
.RegReadI 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: 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 2Here 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.
. .RegDeleteBefore 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: A command to delete: However a command to delete Worse, a command to delete 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 1Firstly, 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:
Summary of Configure the Vista Registry with VBScriptBecause 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.
Watch a Vista Training Video Demo. Windows Vista Registry Tweaks:^
|
||||