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/8 (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.
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.
- Finally, launch WINDIFF open both files and spot the changes in the two files. Here is a link for a refresher on WINDIFF, also to get a copy of WINDIFF
The Goal – Delete All Temporary Files
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 firstname.lastname@example.org
‘ 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\
WScript.Quit ‘ Tells the script to stop and exit.
I like thePermissions Monitor because it enables me to see quickly WHO has permissions to do WHAT. When you launch this tool it analyzes a users effective NTFS permissions for a specific file or folder, takes into account network share access, then displays the results in a nifty desktop dashboard!
Think of all the frustration that this free utility saves when you are troubleshooting authorization problems for users access to a resource. Give this permissions monitor a try – it’s free!
- 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)
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
WScript.Echo "Exporting Successful"
Summary of VBScript Registry Settings
My greatest joy would be if you used this example as a template for changing your registry settings automatically using VBScript.