How to Modify Windows Registry with VBS

Two Visual Basic Scripts

Example 1 is relatively simple. It concentrates on creating objShell and applying the .RegDelete method.

Example 2 is more complex, and introduces limited error correcting code. Moreover Example 2 creates a substitute REG_SZ value, which is the equivalent of renaming IsShortCut.

These scripts are designed for XP and Windows 2003. While they will work on Vista, as noted above, they produce ugly side-effects on icons in the Favorites folder.

Example 1: Basic Script To Remove The Arrow On Shortcuts

Instructions

  • Preliminary step: In order to give the script a chance, create a shortcut. For example, at the desktop, right-click, new, shortcut and type 'calc'. Press 'Finish' and the shortcut, complete with arrow will arrive on the desktop.
  • Copy and paste the script below into notepad, or get a script editor such as OnScript.
  • Save the file with .vbs extension e.g. NoArrowEg1.vbs
  • Double click your VBScript, then 'OK' the message box.
  • To help you understand what is happening in the Registry, I recommend that you launch regedit and navigate to the section specified by strRoot.
  • Ah yes, to actually see the arrows disappear, simply logoff and logon again. The shortcuts should now have no arrows.

' NoArrowEg1.vbs
' Example VBScript to remove arrows on shortcuts in XP
' and Windows 2003.
' Author Guy Thomas http: //computerperformance.co.uk
' Version 1.5 - March 2007
' ---------------------------------------------------------------'
'
Option Explicit
Dim objShell, strRoot, strRead, strDelete, strCreate
strRoot = "HKEY_CLASSES_ROOT\lnkfile\IsShortCut"
' Create the Shell object
Set objShell = CreateObject("WScript.Shell")
strDelete = objShell.RegDelete(strRoot)
WScript.Echo "Error No: " & err.number & " check " & strRoot
strDelete = null
WScript.Quit

' End of example script.

Learning Points

  1. Check how VBScript creates the objShell object, then trace how .RegDelete performs its work on the Registry.
  2. In VBScript HKEY_CLASSES_ROOT can be abbreviated to HKCR. (There is also HKLM and HKCU.) Surprisingly, you cannot use HKCR or HKLM in .Reg files.
  3. The RegDelete method deletes an entry from the Registry based on strName. If strName ends with a backslash (\), then strName is treated as a key, otherwise it is treated as a value.
  4. For completeness, you may wish to find other instances of IsShortCut, for example at: HKCR\piffile and HKCR\WSHFile.