Computer Performance, Windows 2003, Exchange 2003, Logon Scripts

 

VBScript - Change Registry Settings

VBScript to Change the Registry Settings

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:

  1. Change the settings in Internet Explorer, specifically to put a tick in this box:
    'Empty Temporary Internet Files folder when browsing'.
  2. 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.
  3. Then go to Internet explorer and remove the tick from the Export Temporary... checkbox.
  4. Back to Regedit and Export again, this time give your export file a different, e.g. - notick.reg.
  5. 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

Click on the screenshot to expand the thumbnail.Empty Temporary Internet 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"

Script code:

' 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\

objShell.RegWrite RegLocate,"0","REG_DWORD"

WScript.Quit ' Tells the script to stop and exit.

 

Traps for your Script:  Empty Temporary Internet Files

  1. HKEY_Current_User (not HKEY_Local_Machine)
  2. Internet Settings\cache (not Internet\Cache)
  3. Persistent is added to the last part of the path \Cache\Persistent
  4. Persistent = 0 (Not =1)

Guy Recommends: SolarWinds Engineer's Toolset v10Engineer'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.

In fact, I had a real life problem which this technique solved, see here

 .


Google

Webcomputerperformance.co.uk

GFi Events Manager

Guy Recommends: GFi EventsManager

Let GFI EventsManager do the dirty work! Have event logs monitored automatically and get warned about critical events! Download a copy here

 

Home Copyright © 1999-2009 Computer Performance LTD All rights reserved

Please report a broken link, or an error.