Recipe 9.5. Importing Registry Files


Problem

You want to import changes to the Registry using a Registry (.reg) file.

Solution

Using a graphical user interface

  1. Open an Explorer (explorer.exe) window.

  2. Browse to the .reg file you want to import.

  3. Double-click on the file.

  4. Click Yes to confirm the import.

  5. You can accomplish the same thing within Registry Editor by going to File Import.

Using a command-line interface

The following command imports a Registry key or subkey:

> regedit /s <FilePath>

For example:

> regedit /s c:\rallencorp.reg

Using VBScript
' This code imports the contents of a Registry file. ' Since there are no scripting functions to do this, I simply ' shell out to the regedit tool to do it. ' strCommand = "regedit /s <FilePath>" strCommand = "regedit /s c:\rallencorp.reg" set objWshShell = WScript.CreateObject("WScript.Shell") intRC = objWshShell.Run(strCommand, 0, TRUE) if intRC <> 0 then    WScript.Echo "Error returned from importing registry: " & intRC else    WScript.Echo "No errors returned from importing the registry file" end if

Discussion

Importing a Registry file is as easy as double-clicking it, but this is where the danger lies. Be careful anytime you import a Registry file; make sure it contains exactly what you want to import. If you accidentally import the wrong file, it can overwrite values you didn't intend to overwrite. Since Registry files are text-based, open a file in a text editor such as Notepad to see what it contains.



Windows XP Cookbook
Windows XP Cookbook (Cookbooks)
ISBN: 0596007256
EAN: 2147483647
Year: 2006
Pages: 408

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net