Contents of Guy’s Scripting Ezine 8 – Registry Script
- This Week’s Secret
- Scripts to alter registry settings
- Traps for the Empty Temporary Internet Files
- Script Code
- Troubleshooting and Resources
This Week’s Secret is to take you behind the scenes and show you how I create a script by combining skills from different areas. If your goal is to write your own scripts then it’s handy to have a working knowledge of these areas: VBScript (WSH), Windows 2000/3 (utilities), the registry (Regedit), Active Directory (LDAP). I must stress that you just need working knowledge, not expert status; moreover, you do not need to know all of the areas for all of the scripts – build up gradually.
Guy Recommends: The Free IP Address Tracker (IPAT)
Calculating IP Address ranges is a black art, which many network managers solve by creating custom Excel spreadsheets. IPAT cracks this problem of allocating IP addresses in networks in two ways:
For Mr Organized there is a nifty subnet calculator, you enter the network address and the subnet mask, then IPAT works out the usable addresses and their ranges.
For Mr Lazy IPAT discovers and then displays the IP addresses of existing computers. Download the Free IP Address Tracker
I have had several requests to create VBScripts which alter the registry settings. Once you have mastered the technique, the scope for registry scripting is nearly as big as the registry itself. What I want to concentrate on are skills so that you will be able to take a setting like a check box in Explorer, find where that setting is stored in the registry, then write a script to configure it.
Example – to Empty Temporary Internet Files folder
WINDIFF and REGEDIT
I admit frustration crept in when I altered the setting in the registry and nothing happened in Internet Explorer, or when I cleared a tick in the Internet Explorer and nothing seemed to change in the registry.
So I went away, had a cup of tea mowed the lawn, then an idea hit me. Export the registry, use the WINDIFF utility and trace where the settings are really found. Here is the technique I used:
- Change the settings in Internet Explorer – ‘Empty Temporary Internet Files folder when browsing’ so that there is a tick in the box.
- Over to Regedit. Navigate to the section of the registry where that setting is likely to be. 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 remove the tick from the Export Temporary… checkbox.
- Back to Regedit and Export again, this time name your file – notick.reg.
- Finally, launch WINDIFF open both files and spot the changes in the two files.
- Here is a link for your copy of WINDIFF (also more info on WINDIFF)
The Goal was to make sure that the Internet Explorer deleted all temporary files on exit. 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 (Remember other methods like MapNetworkDrive?) 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. (Intuition may tell you it should be =1) "HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Internet Settings\Cache\Persistent"
- HKEY_Current_User (not HKEY_Local_Machine)
- Internet Settings\cache (not Internet\Cache)
- Persistent is added to the last part of the path \Cache\Persistent
- Persistent = 0 (Not =1)
‘ VBScript – contact email@example.com
‘ 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 WSHShell, RegLocate, RegLocate1
Set WSHShell = 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\
WScript.Quit ‘ Tells the script to stop and exit.
- Check this page for your copy of WINDIFF.
- Problems assigning your script? Try this reference.
- Problems with Code 800 errors see – New 800… section.