Jump to content

Recommended Posts

Posted (edited)

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 file : Microsoft, Windows XP Professional, Microsoft Registry 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

:)

multiple into one.reg.cmd.txt

Edited by xfilz
Posted

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

 

'===================
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

Posted

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!

 

'===================
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

:D

Posted

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'...

 

???

:o

Posted

try this

 

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

  • Thanks 1
Posted (edited)

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?

Edited by xfilz
Posted

you will need to use reg query,

 

i found this

Re: Export Registry Value

 

it may help.

 

@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

Posted

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:D

Posted

umm?

 

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

 

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

 

@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

  • Thanks 1
Posted (edited)

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...

:smash:

 


@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... :thumb:

 

 

xfilz

:typing:

Edited by xfilz
  • 6 years later...
  • 1 year later...
Posted (edited)

I was looking to do some of the same things and came to this thread but ended up figuring out a way to do this in PowerShell.

# First get into the path of the registry you want to snag some keys from
set-location -path HKLM:\COMPONENTS\DerivedData\Components

# Get a specific list of keys you need to gather
$COMPATCH = GCI | Where-Object {$_.name -like "*8.0.7601.22921*"}

# Cycle through the targets exporting them by using 'reg' and tagging file names with the name of the key
$COMPATCH | % {
   $RegName = [string]$_
   # Little pre-formatting of the output
   $export = "C:\temp\" + $RegName.split('\')[4] + ".reg"
   # Output of each of the files
   reg export $RegName $export
   # loop
   }

 

Now that you have a zillion of these .reg files you probably don't want to click each of them. So to consolidate them I just loop read and dumped them into a new file.

 

GCI C:\temp | % {
   # Get the contents of the file
   $regcontents = get-content $_

   # Add a return to the file so it doesn't get concatenated by mistake.
   Add-content C:\temp\test.reg "`r"

   # dump the contents into the file
   Add-Content C:\Temp\test.reg $regcontents

   # loop
   }

# In hindsight I should have done a file filter in here but I only had reg files anyway.

 

Now you have one file that has all the entries at once! I was specifically looking for patch related entries as I was attempting to manually repair a bad patch on another system. So I was stealing from a known good system with this method.

Edited by Martel

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now



×
×
  • Create New...