+ Post New Thread
Results 1 to 10 of 10
Scripts Thread, export multiple registry keys and append to one .reg in Coding and Web Development; I have multiple registry keys I like to export and append to one .reg file, instead of several .reg files ...
  1. #1

    Join Date
    Feb 2009
    Posts
    6
    Thank Post
    2
    Thanked 0 Times in 0 Posts
    Rep Power
    0

    Question export multiple registry keys and append to one .reg

    I have multiple registry keys I like to export and append to one .reg file,
    instead of several .reg files that can be imported back into the registry.

    This is my newbie "multiple into one.reg.cmd" example project:

    reg export "HKEY_CURRENT_USER\Environment" .\dump_Environment.reg
    reg export "HKEY_CURRENT_USER\SessionInformation" .\dump_SessionInformation.reg
    reg export "HKEY_CURRENT_USER\Volatile Environment" .\dump_Volatile_Environment.reg
    reg export "HKEY_LOCAL_MACHINE\SYSTEM\MountedDevices" .\dump_MountedDevices.reg
    reg export "HKEY_LOCAL_MACHINE\SYSTEM\Select" .\dump_Select.reg
    reg export "HKEY_LOCAL_MACHINE\SYSTEM\Setup" .\dump_Setup.reg

    It's a bit similar to a problem I found here, but the script is no good/faulty to me:
    VBS script to export multiple registry keys and append to one .reg <b style="color:white;background-color:#886800">file</b> : Microsoft, Windows XP Professional, Microsoft <b style="color:black;background-color:#99ff99">Registry</b> Editor v5.1, VB S
    '================
    Set objShell = CreateObject("WScript.Shell")
    Set objFSO = CreateObject("Scripting.FileSystemObject")

    arrRegPaths = Array( _
    "HKEY_CURRENT_USER\Network\", _
    "HKEY_CURRENT_USER\Printers\", _
    "HKEY_CURRENT_USER\Software\ODBC\", _
    "HKEY_LOCAL_MACHINE\Software\ODBC\" _
    )

    Const intForReading = 1
    Const intUnicode = -1

    strFileName = objShell.ExpandEnvironmentStrings("%UserProfile%") & "\Desktop\RegKeys.reg"

    For Each strRegPath In arrRegPaths
    strCommand = "cmd /c REG EXPORT " & strRegPath & " " & Replace(strRegPath, "\", "_") & ".reg"
    objShell.Run strCommand, 0, True
    Set objRegFile = objFSO.CreateTextFile(strFileName, True, True)
    objRegFile.WriteLine "Windows Registry Editor Version 5.00"
    If objFSO.FileExists(Replace(strRegPath, "\", "_") & ".reg") = True Then
    'WScript.Sleep 1000 ' Wait one second to give the file time to close
    Set objInputFile = objFSO.OpenTextFile(Replace(strRegPath, "\", "_") & ".reg", intForReading, False, intUnicode)
    If Not objInputFile.AtEndOfStream Then
    objInputFile.SkipLine
    objRegFile.Write objInputFile.ReadAll
    End If
    objInputFile.Close
    Set objInputFile = Nothing
    objFSO.DeleteFile Replace(strRegPath, "\", "_") & ".reg", True
    End If
    objRegFile.Close
    Set objRegFile = Nothing
    Next

    MsgBox "Finished."
    '================
    Anyone have knowledge on how to merge/append my example into a better
    "multiple into one.reg.cmd" that fully automates the outcome to one .reg file?

    thanx
    Attached Files Attached Files
    Last edited by xfilz; 6th February 2009 at 12:22 AM.

  2. #2
    box_l's Avatar
    Join Date
    May 2007
    Location
    Herefordshire
    Posts
    437
    Thank Post
    78
    Thanked 95 Times in 79 Posts
    Rep Power
    63
    Hi, the vbs is fine so i edited it to give you the registry parts you require

    the output file goes to the desktop as regkeys.reg

    this is the new code

    Code:
    '===================
    Set objShell = CreateObject("WScript.Shell")
    Set objFSO = CreateObject("Scripting.FileSystemObject")
    
    arrRegPaths = Array( _
          "HKEY_CURRENT_USER\Environment\", _
          "HKEY_CURRENT_USER\SessionInformation\", _
          "HKEY_CURRENT_USER\Volatile Environment\", _
          "HKEY_LOCAL_MACHINE\SYSTEM\MountedDevices\", _
          "HKEY_LOCAL_MACHINE\SYSTEM\Select\", _
          "HKEY_LOCAL_MACHINE\SYSTEM\Setup\" _
          )
    
    Const intForReading = 1
    Const intUnicode = -1
    
    strFileName = objShell.ExpandEnvironmentStrings("%UserProfile%") & "\Desktop\RegKeys.reg"
    
    Set objRegFile = objFSO.CreateTextFile(strFileName, True, True)
    objRegFile.WriteLine "Windows Registry Editor Version 5.00"
    
    For Each strRegPath In arrRegPaths
          strCommand = "cmd /c REG EXPORT " & strRegPath & " " & Replace(strRegPath, "\", "_") & ".reg"
          objShell.Run strCommand, 0, True
          If objFSO.FileExists(Replace(strRegPath, "\", "_") & ".reg") = True Then
                'WScript.Sleep 1000 ' Wait one second to give the file time to close
                Set objInputFile = objFSO.OpenTextFile(Replace(strRegPath, "\", "_") & ".reg", intForReading, False, intUnicode)
                If Not objInputFile.AtEndOfStream Then
                      objInputFile.SkipLine
                      objRegFile.Write objInputFile.ReadAll
                End If
                objInputFile.Close
                Set objInputFile = Nothing
                objFSO.DeleteFile Replace(strRegPath, "\", "_") & ".reg", True
          End If
    Next
    
    objRegFile.Close
    Set objRegFile = Nothing
    
    MsgBox "Finished."
    '===================
    hope this helped

    BoX

  3. #3

    Join Date
    Feb 2009
    Posts
    6
    Thank Post
    2
    Thanked 0 Times in 0 Posts
    Rep Power
    0

    Thumbs up

    YES! Thank you, it finally works, the main problem was other OS language,
    seeing your edits and trying a few different alternatives - its now GOOD!

    Code:
    '===================
    Set objShell = CreateObject("WScript.Shell")
    Set objFSO = CreateObject("Scripting.FileSystemObject")
    
    arrRegPaths = Array( _
          "HKEY_CURRENT_USER\Environment\", _
          "HKEY_CURRENT_USER\SessionInformation\", _
          "HKEY_CURRENT_USER\Volatile Environment\", _
          "HKEY_LOCAL_MACHINE\SYSTEM\MountedDevices\", _
          "HKEY_LOCAL_MACHINE\SYSTEM\Select\", _
          "HKEY_LOCAL_MACHINE\SYSTEM\Setup\" _
          )
    
    Const intForReading = 1
    Const intUnicode = -1
    
    strFileName = objShell.ExpandEnvironmentStrings(".\") & ".\RegKeys.reg"
    
    Set objRegFile = objFSO.CreateTextFile(strFileName, True, True)
    objRegFile.WriteLine "Windows Registry Editor Version 5.00"
    
    For Each strRegPath In arrRegPaths
          strCommand = "cmd /c REG EXPORT " & strRegPath & " " & Replace(strRegPath, "\", "_") & ".reg"
          objShell.Run strCommand, 0, True
          If objFSO.FileExists(Replace(strRegPath, "\", "_") & ".reg") = True Then
                'WScript.Sleep 1000 ' Wait one second to give the file time to close
                Set objInputFile = objFSO.OpenTextFile(Replace(strRegPath, "\", "_") & ".reg", intForReading, False, intUnicode)
                If Not objInputFile.AtEndOfStream Then
                      objInputFile.SkipLine
                      objRegFile.Write objInputFile.ReadAll
                End If
                objInputFile.Close
                Set objInputFile = Nothing
                objFSO.DeleteFile Replace(strRegPath, "\", "_") & ".reg", True
          End If
    Next
    
    objRegFile.Close
    Set objRegFile = Nothing
    
    MsgBox "Finished."
    '===================
    THANX BoX

    xfilz

  4. #4

    Join Date
    Feb 2009
    Posts
    6
    Thank Post
    2
    Thanked 0 Times in 0 Posts
    Rep Power
    0

    Post

    Is it possible to get a .cmd thing to do the same job? My Norton AntiVirus keeps reporting all
    similar .vbs as '''Malicious script detected''' ''FileSystem Object'' -Activity: 'CreateTextFile'...

    ???

  5. #5
    box_l's Avatar
    Join Date
    May 2007
    Location
    Herefordshire
    Posts
    437
    Thank Post
    78
    Thanked 95 Times in 79 Posts
    Rep Power
    63
    try this

    Code:
    reg export "HKEY_CURRENT_USER\Environment" .\dump_Environment.reg
    reg export "HKEY_CURRENT_USER\SessionInformation" .\dump_SessionInformation.reg
    reg export "HKEY_CURRENT_USER\Volatile Environment" .\dump_Volatile_Environment.reg
    
    reg export "HKEY_LOCAL_MACHINE\SYSTEM\MountedDevices" .\dump_MountedDevices.reg
    reg export "HKEY_LOCAL_MACHINE\SYSTEM\Select" .\dump_Select.reg
    reg export "HKEY_LOCAL_MACHINE\SYSTEM\Setup" .\dump_Setup.reg
    
    copy dump_Environment.reg+dump_SessionInformation.reg+dump_Volatile_Environment.reg+dump_MountedDevices.reg+dump_Select.reg +dump_Setup.reg alldump.reg
    
    del dump_Environment.reg dump_SessionInformation.reg dump_Volatile_Environment.reg dump_MountedDevices.reg dump_Select.reg dump_Setup.reg
    the resulting file (alldump.reg) is a bit untidy, but the file will import just fine

    BoX

  6. Thanks to box_l from:

    xfilz (7th February 2009)

  7. #6

    Join Date
    Feb 2009
    Posts
    6
    Thank Post
    2
    Thanked 0 Times in 0 Posts
    Rep Power
    0

    Post

    Thank you very much, very nice of you! Another thing I cant find anywhere... Is it possible to do the 'opposite' thing,
    for instance if you export [HKEY_CURRENT_USER\Printers] and the only value you want is the "DeviceOld"="xxxxxx"
    in the .reg file, without other subkeys and values like [HKEY_CURRENT_USER\Printers\Connections], is it possible?
    Last edited by xfilz; 7th February 2009 at 11:00 PM.

  8. #7
    box_l's Avatar
    Join Date
    May 2007
    Location
    Herefordshire
    Posts
    437
    Thank Post
    78
    Thanked 95 Times in 79 Posts
    Rep Power
    63
    you will need to use reg query,

    i found this
    Re: Export Registry Value

    it may help.

    Code:
    @echo off
    setlocal
    set rkey=HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion
    set rvalue="RegisteredOwner"
    set regexe=%SystemRoot%\System32\Reg.exe
    for /f "Skip=4 Tokens=3" %%a in ('%regexe% QUERY "%rkey%" /v %rvalue%') do (
    set rdata=%%a
    )
    
    echo %rdata% >c:\tst.txt
    start notepad.exe c:\tst.txt
    endlocal
    this is only for one value though.

    i'll have a look at it on monday for multiple values.

    BoX

  9. #8

    Join Date
    Feb 2009
    Posts
    6
    Thank Post
    2
    Thanked 0 Times in 0 Posts
    Rep Power
    0

    Thumbs up

    Wow, I couldnt find the solution anywhere myself, I tried this and it works perfect!
    @echo off
    setlocal
    set rkey=HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion
    set rvalue="RegisteredOwner"
    set regexe=%SystemRoot%\System32\Reg.exe
    for /f "Skip=4 Tokens=3" %%a in ('%regexe% QUERY "%rkey%" /v %rvalue%') do (
    set rdata=%%a
    )

    set regfile=".\my tst.reg"

    echo REGEDIT4>%regfile%
    echo.>>%regfile%
    echo [%rkey%]>>%regfile%
    echo %rvalue%^="%rdata%">>%regfile%
    echo.>>%regfile%

    start notepad.exe %regfile%

    endlocal
    To make it also include the following values is even more awsome:
    [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion] values "SubVersionNumber"="" "CurrentBuild"="" "InstallDate"= "ProductName"="" "RegDone"="" "RegisteredOrganization"="" "RegisteredOwner"="" "SoftwareType"="" "CurrentVersion"="" "CurrentBuildNumber"="" "BuildLab"="" "CurrentType"="" "CSDVersion"="" "SystemRoot"="" "SourcePath"="" "PathName"="" "ProductId"="" "DigitalProductId"= "LicenseInfo"=
    I suspect its too difficult for me, but getting one "RegisteredOwner" value is huge surprise to me its possible

  10. #9
    box_l's Avatar
    Join Date
    May 2007
    Location
    Herefordshire
    Posts
    437
    Thank Post
    78
    Thanked 95 Times in 79 Posts
    Rep Power
    63
    umm?

    that is the whole key if you want all 20 values, so, back to the other way

    Code:
    reg export "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion" .\dump_current_version.reg
    or am i missing what you want?

    changing rkey and rvalue will allow variety

    Code:
    @echo off
    setlocal
    set rkey=HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion
    set rvalue="RegisteredOwner"
    set regexe=%SystemRoot%\System32\Reg.exe
    for /f "Skip=4 Tokens=3" %%a in ('%regexe% QUERY "%rkey%" /v %rvalue%') do (set rdata=%%a)
    
    set regfile=".\my tst.reg"
    
    echo REGEDIT4>%regfile%
    echo.>>%regfile%
    echo [%rkey%]>>%regfile%
    echo %rvalue%^="%rdata%">>%regfile%
    echo.>>%regfile%
    
    ################################################
    set rvalue1="SubVersionNumber"
    for /f "Skip=4 Tokens=3" %%a in ('%regexe% QUERY "%rkey%" /v %rvalue1%') do (set rdata1=%%a)
    
    echo.>>%regfile%
    echo [%rkey%]>>%regfile%
    echo %rvalue1%^="%rdata1%">>%regfile%
    echo.>>%regfile%
    
    #################################################
    set rvalue2="CurrentBuild"
    for /f "Skip=4 Tokens=3" %%a in ('%regexe% QUERY "%rkey%" /v %rvalue2%') do (set rdata2=%%a)
    
    echo.>>%regfile%
    echo [%rkey%]>>%regfile%
    echo %rvalue2%^="%rdata2%">>%regfile%
    echo.>>%regfile%
    
    #################################################
    set rkey=HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Services\Tcpip\parameters
    set rvalue3="hostname"
    for /f "Skip=4 Tokens=3" %%a in ('%regexe% QUERY "%rkey%" /v %rvalue3%') do (set rdata3=%%a)
    
    echo.>>%regfile%
    echo [%rkey%]>>%regfile%
    echo %rvalue3%^="%rdata3%">>%regfile%
    echo.>>%regfile%
    endlocal
    BoX

  11. Thanks to box_l from:

    xfilz (11th February 2009)

  12. #10

    Join Date
    Feb 2009
    Posts
    6
    Thank Post
    2
    Thanked 0 Times in 0 Posts
    Rep Power
    0

    Lightbulb spaces inbetween

    Changing rkey and rvalue works fine, nice work!!! But if there are spaces inbetween words, values are gone...

    Can anyone please explain why? BoX? Well I found a workaround, but the above code would be easier to use...


    Code:
    @echo off
    setlocal
    
    set rkey=HKEY_LOCAL_MACHINE\SYSTEM\Setup\Pid
    set rvalue="Pid"
    set regexe=%SystemRoot%\System32\Reg.exe
    for /f "Skip=4 Tokens=3" %%a in ('%regexe% QUERY "%rkey%" /v %rvalue%') do (set rdata=%%a)
    
    set regfile=".\my_tst.reg"
    
    echo REGEDIT4>%regfile%
    echo.>>%regfile%
    echo [%rkey%]>>%regfile%
    echo %rvalue%^="%rdata%">>%regfile%
    echo.>>%regfile%
    
    ################################################
    
    set rkey=HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion
    set rvalue1="CurrentVersion"
    for /f "Skip=4 Tokens=3" %%a in ('%regexe% QUERY "%rkey%" /v %rvalue1%') do (set rdata1=%%a)
    
    echo.>>%regfile%
    echo [%rkey%]>>%regfile%
    echo %rvalue1%^="%rdata1%">>%regfile%
    echo.>>%regfile%
    
    ################################################
    
    set rvalue2="ProductId"
    for /f "Skip=4 Tokens=3" %%a in ('%regexe% QUERY "%rkey%" /v %rvalue2%') do (set rdata2=%%a)
    
    echo.>>%regfile%
    echo [%rkey%]>>%regfile%
    echo %rvalue2%^="%rdata2%">>%regfile%
    echo.>>%regfile%
    
    #################################################
    
    Regedit /a .\temp.txt "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion"
    
    Find "RegisteredOrganization" < .\temp.txt >> .\RegisteredOrganization.reg
    Find "RegisteredOwner" < .\temp.txt > .\RegisteredOwner.reg
    Find "ProductName" < .\temp.txt >> .\ProductName.reg
    Find "CSDVersion" < .\temp.txt >> .\CSDVersion.reg
    Find "BuildLab" < .\temp.txt >> .\BuildLab.reg
    
    #################################################
    
    
    regedit /a .\dump_MountedDevices.reg "HKEY_LOCAL_MACHINE\SYSTEM\MountedDevices"
    
    copy my_tst.reg+RegisteredOrganization.reg+RegisteredOwner.reg+ProductName.reg+CSDVersion.reg+BuildLab.reg+dump_MountedDevices.reg alldump.reg
    
    del my_tst.reg RegisteredOrganization.reg RegisteredOwner.reg ProductName.reg CSDVersion.reg BuildLab.reg dump_MountedDevices.reg temp.txt tmp.txt
    
    endlocal
    JSI Tip 2750. How do I export a REGEDIT4 .REG file using Windows 2000, from a command line or batch?
    In Windows 2000, Regedit normally exports a unicode .REG file, with a Windows Registry Editor Version 5.00 heading.
    Using the GUI, you can toggle the drop down box from Registration Files to Win9x/NT4 Registration Files (REGEDIT4).
    I had some trouble with REGEDIT4 vs. REGEDIT5 and merging .reg files but regedit /a solved it...


    xfilz
    Last edited by xfilz; 12th February 2009 at 01:43 AM.



SHARE:
+ Post New Thread

Similar Threads

  1. Deleting a registry file on login
    By spider6986 in forum Windows
    Replies: 3
    Last Post: 21st November 2008, 11:42 AM
  2. Proxy setting reg keys
    By MK-2 in forum Windows
    Replies: 7
    Last Post: 19th September 2008, 04:14 PM
  3. CC3, 2Type and Reg Keys
    By CHR1S in forum Network and Classroom Management
    Replies: 2
    Last Post: 25th April 2008, 05:06 PM
  4. Finding out Multiple Windows Keys
    By mmoseley in forum Network and Classroom Management
    Replies: 2
    Last Post: 30th July 2007, 09:14 AM
  5. deploy a reg file
    By alonebfg in forum Windows
    Replies: 12
    Last Post: 7th November 2006, 10:19 AM

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •