Search code examples
regexpowershellregistry

Error Importing .Reg file using re,exe from Powershell


I am performing an export of HKEY_Current_User using the following command

$path = "C:\Temp"
REG EXPORT HKEY_Current_User  $path\HKEY_Current_User.reg

This works and exports the file

When i try to import the file using the following command

 reg import $path\HKEY_Current_User.reg

I get an exception

"Error accessing the registry"

I am running my powershell script from the cmd.exe line and i ran the cmd.exe as administrator.

Any ideas?

Part 2

Is there a way to export the entire registry using reg.exe?

Thanks


Solution

  • You could use regedit by sending it commandline arguments.

    regedit /E C:\Temp\backup.reg "HKEY_CURRENT_USER"

    Ref: https://ss64.com/nt/regedit.html