Back up specific registry key and not any of its subkeys


  1. Posts : 425
    Windows 10
       #1

    Back up specific registry key and not any of its subkeys


    Hi,

    I want to back up
    [HKEY_CURRENT_USER\Software\Valve\Steam]

    But under this are several other sub-keys such as;
    [HKEY_CURRENT_USER\Software\Valve\Steam\ActiveProcess]
    [HKEY_CURRENT_USER\Software\Valve\Steam\Apps]
    [HKEY_CURRENT_USER\Software\Valve\Steam\Apps\1197650]
    and so on.

    I want just the root key and not the sub keys and doing this from a command line in a back up script.

    Possible?
      My Computer


  2. Posts : 18,044
    Win 10 Pro 64-bit v1909 - Build 18363 Custom ISO Install
       #2

    Hello @Wobitancrawfodi,

    I do NOT have Steam so I could NOT create the actual command and test it for you, but by way of an EXAMPLE, and to give you an idea of what you want, Copy & Paste the following command into a CMD Prompt and press Enter.

    It will create a REG_Key_Out.log file on your Desktop. If you have a relocated Desktop, then change the output Path accordingly.

    Code:
    
    PowerShell "$Key='HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion'; Get-ItemProperty -Path $Key -Name *" > %UserProfile%\Desktop\REG_Key_Out.log

    I hope this helps.
    Last edited by Paul Black; 05 Dec 2022 at 08:09.
      My Computer


  3. Posts : 776
    Windows 7
       #3

    [EDITED] - Switched to attached file, because TenForums' editor keeps eating special characters in quoted text...

    PowerShell script inside CMD to check if the reg path exists, export it using reg.exe and then copy output until it hits [path\..] which is the start of subkeys. I don't know which is worse, escaping the special characters for CMD or TenForums mangling my copied text.


    C:\Users\GARLIN\Documents>NoSubKeys.cmd HKEY_CURRENT_USER\Software\Valve\Steam
    Windows Registry Editor Version 5.00

    [HKEY_CURRENT_USER\Software\Valve\Steam]
    "Language"="english"
    "SteamExe"="c:/program files (x86)/steam/steam.exe"
    "SteamPath"="c:/program files (x86)/steam"
    "SuppressAutoRun"=dword:00000000
    "Restart"=dword:00000000
    "RunningAppID"=dword:00000000
    "BigPictureInForeground"=dword:00000000
    "SourceModInstallPath"="C:\\Program Files (x86)\\Steam\\steamapps\\sourcemods"
    "Rate"="30000"
    "AlreadyRetriedOfflineMode"=dword:00000000
    "AutoLoginUser"="----------------"
    "DWriteEnable"=dword:00000001
    "StartupMode"=dword:00000000


    C:\Users\GARLIN\Documents>NoSubKeys.cmd HKEY_CURRENT_USER\Software\Valve\Steam > saved.reg

    C:\Users\GARLIN\Documents>NoSubKeys.cmd HKEY_CURRENT_USER\Software\Valve\Stream
    HKEY_CURRENT_USER\Software\Valve\Stream doesn't exist
    Back up specific registry key and not any of its subkeys Attached Files
    Last edited by garlin; 05 Dec 2022 at 21:40.
      My Computer


  4. Posts : 425
    Windows 10
    Thread Starter
       #4

    Thanks all for your efforts.
    The first one from Mr Black creates a nicely formatted output, which does only contain the root key. Unfortunately, it's not a reg file that can be imported back after the PC is refreshed.

    The second example, nosubkeys.cmd produces a 21mb file with all subkeys contained. This one is a reg file. Unfortunately I only want the root key.

    For the sake of consistency I used the same path for each test;
    HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion

    When I tried nosubkeys.cmd on the path I actually wanted it worked perfectly.

    One small note; The remove-item at the end of the powershell command doesn't work. It leaves the temp.reg file.

    No biggie. I can delete it.

    thanks for your help.
      My Computer


  5. Posts : 15,485
    Windows10
       #5

    The obvious way you can do this is to make a backup of the registry, delete all the subkeys and then backup root key, then restore the backup registry.

    Why would you want to do this though?
      My Computer


  6. Posts : 776
    Windows 7
       #6

    Wobitancrawfodi said:
    One small note; The remove-item at the end of the powershell command doesn't work. It leaves the temp.reg file.
    Thanks. I forgot the use of "break" stops execution before the Remove-Item. I've updated the ZIP to add a CMD check for cleaning up temp.reg.

    This is one of those problems, where the answer will either be too simple or complicated. reg.exe obviously exports the whole subtree below a given key, but it can't be restricted to one level. While you can use PS or other language to walk the registry and pull one level of keys, there isn't a standard "export to REG format".

    For a path like HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion, you will be pulling a lot of subkeys just to throw away the junk. But you asked for a scripted backup, so the extra wait is balanced against the script is easy to audit.
      My Computer


  7. Posts : 425
    Windows 10
    Thread Starter
       #7

    cereberus said:
    Why would you want to do this though?
    I have a couple dozen PCs I'm upgrading from 1809 to 21H2.
    The expectation is that the PC is as close as possible to it's previous state in terms of installed applications, configurations et al.
    I never do inplace upgrades. Not with Microsoft products. Always a clean fresh install.
    The entire process is automated. I fire off the installation of Windows and come back later and finish off with the few programs that can't silently install (semi-automated)
    This steam key was just one example of keys that contain settings that I want to preserve, in this case the default login name and the save password setting.
    Typically, after I've set up the script it can be reused, but for the user, if they have to reinstall anything, it won't be much. Things are essentially how they had them when they gave me the PC.

    - - - Updated - - -

    garlin said:
    This is one of those problems, where the answer will either be too simple or complicated. reg.exe obviously exports the whole subtree below a given key, but it can't be restricted to one level. While you can use PS or other language to walk the registry and pull one level of keys, there isn't a standard "export to REG format".

    For a path like HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion, you will be pulling a lot of subkeys just to throw away the junk. But you asked for a scripted backup, so the extra wait is balanced against the script is easy to audit.
    Hey, no complaints from me. I am grateful for the assistance. I would never have been able to write the script you wrote. Above my pay grade :)
      My Computer


 

  Related Discussions
Our Sites
Site Links
About Us
Windows 10 Forums is an independent web site and has not been authorized, sponsored, or otherwise approved by Microsoft Corporation. "Windows 10" and related materials are trademarks of Microsoft Corp.

© Designer Media Ltd
All times are GMT -5. The time now is 03:18.
Find Us




Windows 10 Forums