Compare registry with .reg files

2

I have recently merged multiple .reg files into a single .reg file but I would like to compare on another machine if these entries already exist before doing an import.

Is this at all possible? I have used registry snapshot tools before but I want to compare a live registry against a reg file with multiple entries.

teaton

Posted 2018-09-06T20:00:39.500

Reputation: 21

reg /query is a starting point. See Reg - Edit Registry - Windows CMD - SS64.com – DavidPostill – 2018-09-06T20:23:05.930

1The PowerShell Compare-Object cmdlet may also prove helpful if you use reg.exe to export the current to a reg file and compare it against an exported .reg file or files. – HelpingHand – 2018-09-06T20:59:47.567

Answers

1

Open your Registry Editor on the target PC with
Win-R
and export all to the filename of your choice with File | Export | All
The .REG extension is acceptable, for the .REG file is plaintext.

Close the Registry Editor, and then run kdiff, an Open Source comparison tool. Open the two files to compare; the differences will be shown in violet by default.

K7AAY

Posted 2018-09-06T20:00:39.500

Reputation: 6 962

1

I realize this is an old post, but I'm hoping this might help someone.

I needed to be able to compare a .reg file to current values in the registry using PowerShell, but the problem I was having was that exporting registry keys for the comparison didn't always export them in the same order that they were in the .reg file I wanted to compare to. So the files may have been effectively identical, a string comparison on the raw file showed that they were different. While some advanced GUI tools might be able to sort it out and do a comparison regardless of the order of the reg keys in the .reg files, that doesn't help when it comes to automating like I was trying to do.

After a fair amount of playing around in PowerShell I found a solution that works quite well:

$liveKey = 'HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\'    #The live key you want to compare

$livePath = 'C:\temp\live.reg'    #Temporary location for the exported reg file
$compareToPath = 'C:\temp\compareTo.reg'    #The .reg file to compare to

REG EXPORT $liveKey $livePath

$compareToFile = ((Get-Content $compareToPath -Raw) -split "`r`n`r`n" | Sort-Object) -join "`r`n`r`n"
$liveFile = ((Get-Content $livePath -Raw) -split "`r`n`r`n" | Sort-Object) -join "`r`n`r`n"

$liveFile -eq $compareToFile    #This will return True if they are the same, $false if they are different.

If you want to see the specific differences just don't rejoin the array and use Compare-Object:

$liveKey = 'HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\'    #The live key you want to compare

$livePath = 'C:\temp\live.reg'    #Temporary location for the exported reg file
$compareToPath = 'C:\temp\compareTo.reg'    #The .reg file to compare to

REG EXPORT $liveKey $livePath

$compareToFile = (Get-Content $compareToPath -Raw) -split "`r`n`r`n" | Sort-Object
$liveFile = (Get-Content $livePath -Raw) -split "`r`n`r`n" | Sort-Object

Compare-Object $liveFile $compareToFile    #The output isn't pretty so if you need to know specific differences, you'll have to play with it a bit to get what you want

The important parts are these two lines:

$compareToFile = ((Get-Content $compareToPath -Raw) -split "`r`n`r`n" | Sort-Object) -join "`r`n`r`n"
$liveFile = ((Get-Content $livePath -Raw) -split "`r`n`r`n" | Sort-Object) -join "`r`n`r`n"

Basically, what we're doing here is reading the .reg file as a single string, splitting it into an array wherever there are two line breaks (.reg exports always have two line breaks between keys), sorting the array, and then joining it back together in a single string. Then since both strings are sorted the same way, the comparison is just a simple string comparison.

GeekLevel9000

Posted 2018-09-06T20:00:39.500

Reputation: 11

0

From the "live registry" to an exported .reg file is just a single step and easily done.

From there, comparison is simple.

There will be no substantive difference between the "live" registry and an exported .reg file, so unless you have unique and compelling reasons to not export for the purpose of easier comparison, it's not necessary to make this additional step.

To use this in a command line or automated process, use reg export to create the export file, and then PowerShell's Compare-Object to do the comparison.

music2myear

Posted 2018-09-06T20:00:39.500

Reputation: 34 957