Help using reg.exe

Discussion in 'Scripting' started by Tito, Aug 26, 2012.

  1. Tito

    Tito Super Mod / Adviser
    Staff Member

    Nov 30, 2009
    18,681
    18,587
    340
    #1 Tito, Aug 26, 2012
    Last edited by a moderator: Apr 20, 2017
    I want to backup the following info using reg.exe in cmd:

    Code:
    [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion]
    "EditionID"="Enterprise"
    "ProductName"="Windows 8 Enterprise"
    
    But if I use the built in export command then it backups all keys & values under CurrentVersion; no way to specify a particular portion. :(

    Code:
    Microsoft Windows [Version 6.2.9200]
    (c) 2012 Microsoft Corporation. All rights reserved.
    
    
    C:\Users\Tito>reg export "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion" D:\backup.reg
    The operation completed successfully. 
    
    Please help.

    :confused:
     
  2. user_hidden

    user_hidden MDL Expert

    Dec 18, 2007
    1,034
    1,061
    60
    i think the REG.exe or REGEDIT.exe both via command line backup the complete key and subkeys, as you are experiencing.

    as far as i know physically running regedit going to your key and right click EXPORT is the only way.

    this link to some VBS code may help: http://www.motobit.com/help/regedit/sa310.htm
     
  3. Tito

    Tito Super Mod / Adviser
    Staff Member

    Nov 30, 2009
    18,681
    18,587
    340
    Thanks for the help!!!

    But I want to code it entirely in CMD... ok thinking of an alternate way :g:
     
  4. searchengine

    searchengine Guest

    #4 searchengine, Aug 26, 2012
    Last edited by a moderator: Apr 20, 2017
    reg query 'ProductName' & 'EditionId' entries, and write results to 'Backup.reg'

    Code:
    @ECHO OFF
    
    SET PRDT=&SET EDTN=
    
    ::reg query 'ProductName' & 'EditionId' entries
    FOR /F "tokens=2* delims= " %%A IN ('REG QUERY "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion" /v ProductName') DO SET PRDT=%%B
    FOR /F "tokens=2* delims= " %%A IN ('REG QUERY "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion" /v EditionId') DO SET EDTN=%%B
    
    ::write 'Backup.reg'
    (ECHO Windows Registry Editor Version 5.00
    ECHO.
    ECHO [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion]
    ECHO "EditionID"="%EDTN%"
    ECHO "ProductName"="%PRDT%") >Backup.reg
     
  5. Tito

    Tito Super Mod / Adviser
    Staff Member

    Nov 30, 2009
    18,681
    18,587
    340
    #5 Tito, Aug 26, 2012
    Last edited by a moderator: Apr 20, 2017
    (OP)
    Exactly what I want to do!!!

    Thanks a lot!!!

    :worthy:
     
  6. racky29

    racky29 MDL Senior Member

    Aug 2, 2007
    285
    93
    10
  7. user_hidden

    user_hidden MDL Expert

    Dec 18, 2007
    1,034
    1,061
    60
    great job ;)
     
  8. Tito

    Tito Super Mod / Adviser
    Staff Member

    Nov 30, 2009
    18,681
    18,587
    340
    Indeed... ;)
     
  9. Tito

    Tito Super Mod / Adviser
    Staff Member

    Nov 30, 2009
    18,681
    18,587
    340
    Please take a look here... my first batch :rolleyes:
     
  10. Tito

    Tito Super Mod / Adviser
    Staff Member

    Nov 30, 2009
    18,681
    18,587
    340
  11. searchengine

    searchengine Guest

    very good ;)

    I would suggest a small change to Winrar sfx... Path=%temp%\UpDown8
    I would change this 'Path' to... Path=%windir%\UpDown8

    If 'Backup.reg' saved to '%temp%' location it will most likely be deleted, by Windows Cleanup, CCleaner, Etc.
     
  12. burfadel

    burfadel MDL EXE>MSP/CAB

    Aug 19, 2009
    2,627
    3,856
    90
    #12 burfadel, Aug 27, 2012
    Last edited by a moderator: Apr 20, 2017
    I had a look at you UpDown8 script.

    Instead of importing the .reg files, such that it is:

    Code:
    Windows Registry Editor Version 5.00
    
    [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion]
    "EditionID"="Enterprise"
    "ProductName"="Windows 7 Enterprise"
    You can do it internally in the script file by:

    Code:
    reg add "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion" /t REG_SZ /v EditionID  /d Enterprise /f>nul
    reg add "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion" /t REG_SZ /v ProductName /d "Windows 7 Enterprise" /f>nul
    
    the errorlevel codes still apply, 0 success, 1 fail. The /f overwrites the existing values, just as it does when you import a .reg file.

    you can do the same with the other two files. Not that it really matters, but a Windows based batch script I believe should be named with the .cmd extension.