Recipe9.5.Importing Registry Files


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 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 unintentionally overwrite values. Since registry files are text based, open a file in a text editor such as Notepad to see what it contains.



Windows Server Cookbook
Windows Server Cookbook for Windows Server 2003 and Windows 2000
ISBN: 0596006330
EAN: 2147483647
Year: 2006
Pages: 380
Authors: Robbie Allen

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