Our
mission is to create a script that will change values in the registry.
Once you have mastered the technique, the scope for registry scripting is nearly
as big as the registry itself. The mission will be tricky, success will
depend on attention to detail.
To complete our mission, we are going to need to combine skills from VBScript (WSH), Windows 2003/3 (Windiff, the registry (Regedit, Active Directory (LDAP). In
truth, I selected this key for you to experiment with scripting the registry using a relatively harmless key.
Example - To Empty Temporary Internet Files folder
The
scenario is this, we need to control the follow setting in the browser -
'Empty Temporary Internet Files folder when browsing'.
WINDIFF and REGEDIT
The method we are going to use involves exporting a section of the registry.
In fact we will export the section twice, once with setting on (checked) and
once with the setting off (unchecked).
Now we are ready to open the WINDIFF utility an detect the difference in the
two files. Once we locate the differences between the checked and
unchecked files we will know where in the registry the setting is located.
Here is the technique I used:
Change the settings in Internet Explorer, specifically to put a tick in this box: 'Empty Temporary Internet Files
folder when browsing'.
Next, over to Regedit. Navigate to the section of the registry where that
setting is likely to be found. HKEY_CURRENT_USER_Software_Microsoft, Right Click, then Select Export
on the shortcut menu. Choose a suitable filename e.g. tick.reg.
Then go to Internet explorer and remove the tick from the Export Temporary...
checkbox.
Back to Regedit and Export again, this time give your export file a different, e.g. - notick.reg.
Remember that the Goal was to make sure that the Internet Explorer deleted all temporary
files on exit. We want a script which does the same as manually clicking, IE, Tools, Internet Options, Advanced, Security, Empty Temporary
Internet Files on Exit.
RegWrite - WSH Method
The actual scripting part is controlled by a method called RegWrite. Once WINDIFF told me the
correct registry path, it is a matter of taking care with the syntax and
using REG_DWORD (not REG_SZ).
There was one last trap to get the
tick to appear in Internet Explorer you need to set Persistent = 0.
The logic is we do not want any files saved - hence zero.
"HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Internet
Settings\Cache\Persistent"
' VBScript - contact guy@computerperformance.co.uk
' The script writes to the registry value: Empty Temporary Internet Files
' The key Method is RegWrite. RegLocate is the name of the variable
' Note: REG_DWORD (not REG_SZ)
' Note: Logic of 0 (zero = off) means persistent ON - strange but true!
Dim objShell, RegLocate, RegLocate1
Set objShell = WScript.CreateObject("WScript.Shell")
On Error Resume Next
RegLocate = "HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Internet
Settings\Cache\Persistent"
' Take great care with the line above
' Note the space between \Internet and Settings\
Persistent is added to the last part of the path \Cache\Persistent
Persistent = 0 (Not =1)
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
Registry Export Script - Kindly Sent by Michael Einar Reynis
'strCommand = "regedit /e <FilePath> <RegKey>" Set wshShell =
WScript.CreateObject( "WScript.Shell" ) strCommand = "regedit /e C:\%USERNAME%.reg
HKEY_LOCAL_MACHINE\SOFTWARE\Symantec" set objWshShell =
WScript.CreateObject("WScript.Shell") intRC = objWshShell.Run(strCommand,
0, TRUE) if intRC <> 0 then WScript.Echo "Error returned from
exporting registry: " & intRC else WScript.Echo "Exporting Successful"
end if
Summary for RegWrite
My greatest joy would be if you used this example as a template for changing
your registry settings automatically using VBScript.