Creating the WshShell Object

To use the Reg.exe tool to back up the registry, it is necessary to create an instance of the WshShell class. This allows you to launch programs that are not part of Windows Scripting Host. The following program, RegBack.vbs, illustrates making a hook into WshShell:

Option Explicit
dim objShell

WScript.Echo("beginning " & Now)
Set objShell = CreateObject("WScript.Shell")
objShell.Exec "%comspec% /k reg.exe EXPORT HKLM c:\hklm.reg"
WScript.Echo("completed " & Now)

As you can see in RegBack.vbs, you declare a variable called objShell and set it equal to the hook that comes back from using CreateObject to create an instance of WshShell.

After we have this hook into the Shell object, you use the Exec method to launch a command-line ...

Get Microsoft® Windows® Scripting Self-Paced Learning Guide now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.