Click here to Skip to main content
15,918,168 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
How can i export only a single reg entry from a reg key? I dont need all the subkeys or entries or values to be exported. Just a specific single reg entry. I tried reg export but it exports the whole reg key with whole reg subkeys and other entries as well. Please suggest any command in CMD prompt or C# or powershell or bat file script or any script, which can accomplish this. Please refer to the attached image, where i just want to export "Test" reg entry and not the "Dinesh" or anything else.
<a href="https://i.stack.imgur.com/YfsbQ.png">Reg_Snapshot</a>

Expectation: The exported .reg file should just contain this information:

Windows Registry Editor Version 5.00

[HKEY_LOCAL_MACHINE\SOFTWARE\Dinesh]

"Test"="Hello"

Please suggest simple solution to this problem. I have other workarounds in mind to achieve this but those will be lot of work. Looking for simple way (if exists).

What I have tried:

Tried Reg export, reg save, but they didnt give desired output.

Commands, I have tried:

Microsoft Windows [Version 10.0.19045.2604]
(c) Microsoft Corporation. All rights reserved.

C:\WINDOWS\system32>reg.exe export "HKLM\Software\Dinesh\Test" "C:\Temp\Dell_Reg\Dell_Test.reg" /y
ERROR: The system was unable to find the specified registry key or value.

C:\WINDOWS\system32>reg.exe export "HKEY_LOCAL_MACHINE\Software\Dinesh\Test" "C:\Temp\Dell_Reg\Dell_Test.reg" /y
ERROR: The system was unable to find the specified registry key or value.

C:\WINDOWS\system32>reg.exe export "HKEY_LOCAL_MACHINE\Software\Dinesh" "C:\Temp\Dell_Reg\Dell_Test.reg" /y
The operation completed successfully.

C:\WINDOWS\system32>reg.exe export "HKLM\Software\Dinesh" "C:\Temp\Dell_Reg\Dell_Test1.reg" /y
The operation completed successfully.

C:\WINDOWS\system32>regedit /e"C:\Temp\Dell_Reg\Test1.reg" "HKLM\Software\Dinesh\Test"

C:\WINDOWS\system32>regedit /e"C:\Temp\Dell_Reg\Test1.reg" "HKEY_LOCAL_MACHINE\Software\Dinesh\Test"

C:\WINDOWS\system32>reg.exe save "HKLM\Software\Dinesh\Test" "C:\Temp\Dell_Reg\Dell_Test2.hiv" /y
ERROR: The system was unable to find the specified registry key or value.

C:\WINDOWS\system32>reg.exe save "HKLM\Software\Dinesh\Test*" "C:\Temp\Dell_Reg\Dell_Test2.reg" /y
ERROR: The system was unable to find the specified registry key or value.

C:\WINDOWS\system32>reg.exe save "HKLM\Software\Dinesh\Test" "C:\Temp\Dell_Reg\Dell_Test2.hiv" /y
ERROR: The system was unable to find the specified registry key or value.

C:\WINDOWS\system32>reg.exe save "HKLM\Software\Dinesh" "C:\Temp\Dell_Reg\Dell_Test2.hiv" /y
The operation completed successfully.

C:\WINDOWS\system32>reg export HKLM\Software\Dinesh C:\export.txt && type C:\export.txt | findstr /i "test"
The operation completed successfully.
"Test"="Hello"
Posted
Updated 25-Mar-23 7:14am
v4

 
Share this answer
 
v2
Comments
Dinesh Kumar Dora 3-Mar-23 9:17am    
The term 'Export-Registry' is not recognized as the name of a cmdlet
Richard MacCutchan 3-Mar-23 9:20am    
I guess you did not bother to read the complete page. But using "REG EXPORT" in a command window is probably easier.
Dinesh Kumar Dora 3-Mar-23 9:28am    
"REG EXPORT" in a command window also didnt work
Richard MacCutchan 3-Mar-23 9:34am    
Well unless you show the exact command you use and the resulting output we have no way of guessing what is wrong.
Dinesh Kumar Dora 3-Mar-23 9:51am    
Hi Richard, respectfully - I am not sure whether you understood my question/requirement. I wanted to export the reg entry to a reg file, so that it can be imported back directly. I can fetch the values in multiple ways, but i dont want to do that, due to some technical constraints. I simply want a way to export a specific registry entry to a .reg file.
Understand that this is true said by Dave-Kreskowiak
You cannot export a single value. You would have to write your own tool to do that

A bat would do that, but use a filter and a temp file:
@echo off

set "_hkey=HKLM\SOFTWARE\Dinesh"
>nul reg export "%_hkey%" "%tmp%\TMPDinesh.reg" /y

>"C:\Temp\Dell_Reg\Dell_Test.Reg" (
        type "%tmp%\TMPDinesh.reg" | findstr /v Dinesh.=
      ) 

del /q /f /a "%tmp%\RegExportDinesh.reg"

Output (content) resulting in the file:
Windows Registry Editor Version 5.00

[HKEY_LOCAL_MACHINE\SOFTWARE\Dinesh]
"Test"="Hello"
After exporting and filtering, generating your reg file, then you can import:
Reg import "C:\Temp\Dell_Reg\Dell_Test.Reg"
 
Share this answer
 
v3
Comments
Line Item 20-Mar-24 21:44pm    
@Dave-Kreskowiak, would please put that into code for C and for C++11? Thank you.
You can't. There is no tool that comes with Windows that will export anything other than an entire key and all of its sub-keys and values.

You cannot export a single value. You would have to write your own tool to do that.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900