is there a way to export registry key but in an incremental way , many copies ?


Recommended Posts

Hi

i would to export some registry key with a bat file but in incremental way  (keep many reg files , with a name and a suffix for example export1.reg export2.reg and so on ) ?

I 'm thinking about a bat file ,just because i can use the windows 11 or 10 task manager and run every x hours or every day

i don't want to export the entire registry but only 1 key or 2 ,with all the subkeys and keep all them

I use a free portable backup jubut portable , cool program ,but only for files, and macrium for image

i'm looking for a script / bat , can a script/bat file do it?

I have't found a free program to export them

thanks

@echo off
setlocal enabledelayedexpansion

set /p "numKeys=Enter the number of registry keys to export: "
set /p "backupDir=Enter the backup directory path: "

if not exist "%backupDir%" mkdir "%backupDir%"

set "baseFileName=export"
set "fileExt=.reg"
set "counter=1"

for /l %%i in (1,1,%numKeys%) do (
    set /p "key%%i=Enter the location of registry key #%%i: "
)

:loop
set "fileName=%baseFileName%!counter!%fileExt%"
set "filePath=%backupDir%\!fileName!"

for /l %%i in (1,1,%numKeys%) do (
    reg export "!key%%i!" "!filePath!" /y
)

set /p "continue=Do you want to export another set of registry keys? (Y/N): "
if /i "!continue!"=="Y" (
    set /a "counter+=1"
    goto loop
)

 

  On 21/04/2024 at 08:15, cacoe said:

 

Expand  

hi Cacoe

may i a question ?

let's say i want to backup these keys 

  Quote

HKEY_CURRENT_USER\Software\Mozilla

Expand  

to X:\backupregistry

is your script correct ?

I have added HKEY_CURRENT_USER\Software\Mozilla 

the backup folder is X:\backupregistry

about the number of registry key to export what does it mean how many backups?

thanks Caoce

@echo off
setlocal enabledelayedexpansion

set /p "numKeys=Enter the number of registry keys to export: "
set /p "backupDir=x:\backupregisry: "

if not exist "%backupDir%" mkdir "%backupDir%"

set "baseFileName=export"
set "fileExt=.reg"
set "counter=1"

for /l %%i in (1,1,%numKeys%) do (
    set /p "key%%i=HKEY_CURRENT_USER\Software\Mozilla #%%i: "
)

:loop
set "fileName=%baseFileName%!counter!%fileExt%"
set "filePath=%backupDir%\!fileName!"

for /l %%i in (1,1,%numKeys%) do (
    reg export "!key%%i!" "!filePath!" /y
)

set /p "continue=Do you want to export another set of registry keys? (Y/N): "
if /i "!continue!"=="Y" (
    set /a "counter+=1"
    goto loop
)

 

## Export registry key

# Specify registry key
$registryKey = "HKEY_CURRENT_USER\Software\Mozilla"

# Specify the path to save .reg file
$exportPath = "X:\backupregistry\Mozilla.reg"

# Export the registry key
Invoke-Expression -Command "reg export `"$registryKey`" `"$exportPath`""

# Check if the export was successful
if (Test-Path -Path $exportPath) {
    Write-Host "Registry key exported successfully."
} else {
    Write-Host "Failed to export registry key."
}

Save as <filename>.ps1, run with PowerShell.

  • Thanks 2
  On 21/04/2024 at 11:44, binaryzero said:
## Export registry key

# Specify registry key
$registryKey = "HKEY_CURRENT_USER\Software\Mozilla"

# Specify the path to save .reg file
$exportPath = "X:\backupregistry\Mozilla.reg"

# Export the registry key
Invoke-Expression -Command "reg export `"$registryKey`" `"$exportPath`""

# Check if the export was successful
if (Test-Path -Path $exportPath) {
    Write-Host "Registry key exported successfully."
} else {
    Write-Host "Failed to export registry key."
}

Save as <filename>.ps1, run with PowerShell.

Expand  

Hi @binaryzero  @cacoe

if i click on run with powershell it does work ,I have tried even  in power shell ISE and the error translated in English with google translator is

Failed to load file X:\backupregistryJriver\eportaregistryJriver.ps1. Script execution is disabled on your system. For more information,
see about_Execution_Policies at https://go.microsoft.com/fwlink/?LinkID=135170.
    + CategoryInfo : Protection error: (:) [], ParentContainsErrorRecordException
    + FullyQualifiedErrorId : UnauthorizedAccess

here a command

  Quote

 Get-ExecutionPolicy -List

        Scope ExecutionPolicy
        ----- ---------------
MachinePolicy       Undefined
   UserPolicy       Undefined
      Process       Undefined
  CurrentUser       Undefined
 LocalMachine       Undefined

Expand  

so i opened powershell as administrator windows 11 pro , and copied everything it does create it but only 1 registry backup

i would like to create many backups and only 1

could be make maybe with the bat/cmd  files many files (i have no limit)?

thanks

Set-ExecutionPolicy unrestricted

# Import CSV file
$csvData = Import-Csv -Path "X:\backupregistry\regkeys.csv"

# Backup directory
$backupDir = "X:\backupregistry"

# Check the backup directory exists
if (!(Test-Path -Path $backupDir)) {
    New-Item -ItemType Directory -Path $backupDir | Out-Null
}

# Loop through each registry key in the CSV file
foreach ($row in $csvData) {
    $key = $row.RegistryKey

    # Define the backup file path
    $backupFile = Join-Path -Path $backupDir -ChildPath ("$(($key -replace '\\', '_')).reg")

    # Export the registry key
    Invoke-Expression -Command "reg export `"$key`" `"$backupFile`""

    # Check if the .reg file has been created
    if (Test-Path -Path $backupFile) {
        Write-Output "Backup for $key created successfully at $backupFile"
    }
    else {
        Write-Output "Failed to create backup for $key"
    }
}

Save as ps1. Create a csv file with the header "RegistryKey", list key paths underneath. 

  On 21/04/2024 at 15:52, binaryzero said:

Set-ExecutionPolicy unrestricted

 

Expand  

hi

i have set unrestricted by default

Get-ExecutionPolicy -List

        Scope ExecutionPolicy
        ----- ---------------
MachinePolicy       Undefined
   UserPolicy       Undefined
      Process       Undefined
  CurrentUser       Undefined
 LocalMachine       Undefined

thanks

  On 21/04/2024 at 09:09, drugo said:

hi Cacoe

may i a question ?

let's say i want to backup these keys 

to X:\backupregistry

is your script correct ?

I have added HKEY_CURRENT_USER\Software\Mozilla 

the backup folder is X:\backupregistry

about the number of registry key to export what does it mean how many backups?

thanks Caoce

@echo off
setlocal enabledelayedexpansion

set /p "numKeys=Enter the number of registry keys to export: "
set /p "backupDir=x:\backupregisry: "

if not exist "%backupDir%" mkdir "%backupDir%"

set "baseFileName=export"
set "fileExt=.reg"
set "counter=1"

for /l %%i in (1,1,%numKeys%) do (
    set /p "key%%i=HKEY_CURRENT_USER\Software\Mozilla #%%i: "
)

:loop
set "fileName=%baseFileName%!counter!%fileExt%"
set "filePath=%backupDir%\!fileName!"

for /l %%i in (1,1,%numKeys%) do (
    reg export "!key%%i!" "!filePath!" /y
)

set /p "continue=Do you want to export another set of registry keys? (Y/N): "
if /i "!continue!"=="Y" (
    set /a "counter+=1"
    goto loop
)

 

Expand  

The number is simply the amount of keys you would like to save, so if you know you want to save 5 keys, enter 5, then you will proceed to get 5 prompts for 5 different key locations, then it will save to 5 different files to the backup location.

All entries under each key will be saved to each file.

  On 21/04/2024 at 17:05, cacoe said:

The number is simply the amount of keys you would like to save, so if you know you want to save 5 keys, enter 5, then you will proceed to get 5 prompts for 5 different key locations, then it will save to 5 different files to the backup location.

All entries under each key will be saved to each file.

Expand  

hi Cacoe

but there is something doesn't work , might you please check it?

thanks

@echo off
setlocal enabledelayedexpansion

set /p "numKeys=5"
set /p "backupDir=x:\backupregistry\"

if not exist "%backupDir%" mkdir "%backupDir%"

set "baseFileName=export"
set "fileExt=.reg"
set "counter=1"

for /l %%i in (1,1,%numKeys%) do (
    set /p "key%%i=HKEY_CURRENT_USER\Software\Mozilla"
)

:loop
set "fileName=%baseFileName%!counter!%fileExt%"
set "filePath=%backupDir%\!fileName!"

for /l %%i in (1,1,%numKeys%) do (
    reg export "!key%%i!" "!filePath!" /y
)

set /p "continue=Do you want to export another set of registry keys? (Y/N): "
if /i "!continue!"=="Y" (
    set /a "counter+=1"
    goto loop
)

 

  On 21/04/2024 at 18:41, drugo said:

hi Cacoe

but there is something doesn't work , might you please check it?

thanks

@echo off
setlocal enabledelayedexpansion

set /p "numKeys=5"
set /p "backupDir=x:\backupregistry\"

if not exist "%backupDir%" mkdir "%backupDir%"

set "baseFileName=export"
set "fileExt=.reg"
set "counter=1"

for /l %%i in (1,1,%numKeys%) do (
    set /p "key%%i=HKEY_CURRENT_USER\Software\Mozilla"
)

:loop
set "fileName=%baseFileName%!counter!%fileExt%"
set "filePath=%backupDir%\!fileName!"

for /l %%i in (1,1,%numKeys%) do (
    reg export "!key%%i!" "!filePath!" /y
)

set /p "continue=Do you want to export another set of registry keys? (Y/N): "
if /i "!continue!"=="Y" (
    set /a "counter+=1"
    goto loop
)

 

Expand  

I don't see the issue, I tested it, it's a batch file, I ran it, set it to only do 1 key, selected a random key and it saved the contents to a reg file. What is not working?

  On 21/04/2024 at 20:50, Dick Montage said:

Would it not make sense to just learn PowerShell? Literally so useful

Expand  

This. 

I provided two code samples, with comments; up to them now...

  • Like 2
  On 21/04/2024 at 22:24, cacoe said:

I don't see the issue, I tested it, it's a batch file, I ran it, set it to only do 1 key, selected a random key and it saved the contents to a reg file. What is not working?

Expand  

hi Cacoe

it does not save any reg files...

i have tried even this key with all the sub keys

for /l %%i in (1,1,%numKeys%) do (
    set /p "key%%i=HKEY_CURRENT_USER\Software\J. River"
)

maybe the problem is this

set "baseFileName=export"
set "fileExt=.reg"
set "counter=1"

i should set  ?

set "fileExt=backup.reg

thanks pal 

  On 21/04/2024 at 15:52, binaryzero said:
# Import CSV file
$csvData = Import-Csv -Path "X:\backupregistry\regkeys.csv"

# Backup directory
$backupDir = "X:\backupregistry"

# Check the backup directory exists
if (!(Test-Path -Path $backupDir)) {
    New-Item -ItemType Directory -Path $backupDir | Out-Null
}

# Loop through each registry key in the CSV file
foreach ($row in $csvData) {
    $key = $row.RegistryKey

    # Define the backup file path
    $backupFile = Join-Path -Path $backupDir -ChildPath ("$(($key -replace '\\', '_')).reg")

    # Export the registry key
    Invoke-Expression -Command "reg export `"$key`" `"$backupFile`""

    # Check if the .reg file has been created
    if (Test-Path -Path $backupFile) {
        Write-Output "Backup for $key created successfully at $backupFile"
    }
    else {
        Write-Output "Failed to create backup for $key"
    }
}
Expand  

Save ^ as "BackupRegistryKeys.ps1".

Create a CSV file called "regkeys.csv", save it in X:\Backupregistry, copy and paste the below.

RegistryKey,
HKEY_CURRENT_USER\Software\Mozilla,
HKEY_CURRENT_USER\Software\J. River,

(or use Excel, save as .csv)

Open PowerShell, run the script, .\BackupRegistryKeys.ps1. Tada

When you want to add more registry keys, add them to the csv file. No need to hardcode paths in the script...

  • Thanks 2

Tidy little script that :) -
(+Extra credit for commenting it properly👍
)

Still surprises me there is no export-item functionality for the registry in PowerShell, you can do everything else - but for exports you still have to call reg.exe
 

Instead of adding number -01 etc index numbers, you could just use the date, if you did that you could have just a 1 liner, something like this:

reg export "HKEY_CURRENT_USER\Software\Mozilla" "X:\backupregistry\%DATE:/=-%.reg" /y

Depending on your local date format you might need to change the format of the date variable to suit, or add the time variable too if you are doing multiple exports per day.

  On 22/04/2024 at 16:08, binaryzero said:

Save ^ as "BackupRegistryKeys.ps1".

Create a CSV file called "regkeys.csv", save it in X:\Backupregistry, copy and paste the below.

RegistryKey,
HKEY_CURRENT_USER\Software\Mozilla,
HKEY_CURRENT_USER\Software\J. River,

(or use Excel, save as .csv)

Open PowerShell, run the script, .\BackupRegistryKeys.ps1. Tada

When you want to add more registry keys, add them to the csv file. No need to hardcode paths in the script...

Expand  

hi

first i want to thank you so much

but i can't understand why under windows 11 pro 64bit , from the extension menu run with powershell it doesn't work

it's just handy

will the script save me many *.reg files , like backup.reg , backup1.reg , backup2.reg and so on

appreciate it a lot 

# Import CSV file
$csvData = Import-Csv -Path "X:\backupregistry\regkeys.csv"

# Backup directory
$backupDir = "X:\backupregistry"

# Check the backup directory exists
if (!(Test-Path -Path $backupDir)) {
    New-Item -ItemType Directory -Path $backupDir | Out-Null
}

# Loop through each registry key in the CSV file
foreach ($row in $csvData) {
    $key = $row.RegistryKey

    # Get the current date and time
    $date = Get-Date -Format "yyyyMMdd_HHmmss"

    # Define the backup file path
    $backupFile = Join-Path -Path $backupDir -ChildPath ("$(($key -replace '\\', '_'))-$date.reg")

    # Export the registry key
    Invoke-Expression -Command "reg export `"$key`" `"$backupFile`""

    # Check if the .reg file has been created
    if (Test-Path -Path $backupFile) {
        Write-Output "Backup for $key created successfully at $backupFile"
    }
    else {
        Write-Output "Failed to create backup for $key"
    }
}

Added a line to append the date and time to the end of the filename; you can change the format yourself, https://lazyadmin.nl/powershell/get-date/.

You're going to need to run this in an elevated PowerShell (run as administrator) session if you're backing up HKLM keys.

If you want to create a shortcut, create BackupRegistryKeys.cmd and put "start %SystemRoot%\system32\WindowsPowerShell\v1.0\powershell.exe -Executionpolicy Bypass -Noninteractive -File "X:\backupregistry\BackupRegistryKeys.ps1". Right click, run as administrator.

Edited by binaryzero

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Posts

    • I mean they have been proven to be safer than human drivers in many cases so at the end of the day they will be allowed on the road, the fact that you don't trust them doesn't mean that policy has to be changed to make you more comfortable I am afraid.
    • This 4TB Gen4 2280 NVMe SSD is selling for just $200 with promo coupon by Sayan Sen We reported yesterday about the WD_BLACK SN8100 (PCIe Gen5) and SN7100 (PCIe Gen4) deals as they are both priced the lowest. There is also a free VPN on offer. You can check those deals out here. If you do not quite have the budget for those drives but still want a relatively fast drive in 4TB, then Team Group is offering its T-FORCE G50 model at a great price of just $200 with a coupon code (purchase link down below). Like the SN8100 and SN7100 WD SKUs, the Team Group G50 is also a TLC (triple level cell) NAND flash SSD, and thus the endurance on the T-FORCE SSD is quite good, as it is rated for 2600 TBW (terabytes written). Its MTBF, or Mean Time Between Failure, is claimed at 3,000,000 hours. However, unlike the WD_BLACK models, the G50 does not have a dedicated DRAM cache (only the G50 Pro SKUs have it) but it is based on NVMe version 1.4 which supports HMB (host memory buffer) technology; thus, the drive can use system memory for caching. In terms of performance, Team Group promises sequential read and write speeds of up to 5000 MB/s and 4500 MB/s, respectively. However, the firm does not disclose random throughput metrics. Essentially, compared to the WD_BLACK SN7100 linked above, you miss out on faster speeds, but you are also paying less with this. Either of these drives can be a great choice depending on your budget. Get the Team Group SSD at the link below: Team Group T-FORCE G50 M.2 2280 4TB PCIe 4.0 x4 - TM8FFE004T0C129: $219.99 + $20 off with promo code SUMET9324, limited offer => $199.99 (Shipped and Sold by Newegg US) This Amazon deal is US-specific and not available in other regions unless specified. If you don't like it or want to look at more options, check out the Amazon US deals page here. Get Prime (SNAP), Prime Video, Audible Plus or Kindle / Music Unlimited. Free for 30 days. As an Amazon Associate, we earn from qualifying purchases.
    • Two Point Hospital is free to claim on the Epic Games Store by Pulasthi Ariyasinghe With the Mega Sale coming to an end, the Epic Games Store has returned to offering its regular giveaways promotion. This week, replacing the Deathloop, Ogu, and Secret Forest freebies, Two Point Hospital has landed for all PC gamers to claim. Coming in from Two Point Studios, this 2018-released hospital building and management game offers a humorous take on the genre and is poised as a spiritual successor to the classic Theme Hospital from 1997. The title has you constructing various rooms that diagnose and treat patients with unique and bizarre illnesses that range from Jazz Hands and Bed Face to Lycanthropy. The hospital staff must also be hired and taken care of with exclusive amenities and pay raises to keep morale high. At the same time, players also must make sure to keep the hospital's reputation and profits in good standing. There are multiple regions to play through, with each hospital in a region giving players different goals and obstacles to tackle. This is the base game that's being given away, but there's plenty of DLC available for those who want even more hospital regions and wacky diseases in their game. Here's how the studio describes the curing illnesses process: Two Point Hospital is now free to claim on the Epic Games Store. The Sega-published title usually costs $29.99 to purchase when not on sale, but here it's yours to keep without paying a dime. The next giveaway in the store, which will arrive as a replacement for this offer, is slated to kick off on June 19.
    • Claim your VideoProc Converter AI v7.5 ($78.90 Value) free license by Steven Parker Claim your free license (worth $78.90) today, before the offer expires on June 18. Download a licensed copy of VideoProc Converter AI V6.4 (for Windows) for free. Equipped with AI tools for video and image enhancement, smoothness, and stabilization. Remaster low-quality videos and photos, convert, edit, compress, download, and record with GPU acceleration! Key Features of VideoProc Converter AI V7.5: AI Video Upscaling: Upscale low-res, old, grainy videos/DVDs/recordings by 400% to HD/4K for stunning visuals on larger screens. AI Image Enhancement: Upscale images and AI art to 8K/10K for better cropping, editing, printing, and sharing. AI Stabilization: Intelligently stabilize shaky GoPro/drone/camera footage with controllable cropping ratios. AI Frame Interpolation: Boost FPS from 30/60 to silky-smooth 120/240/480, or create epic slow-motion effects. 5-in-1 Video Toolkit: Convert, edit, compress, download, and record with the highest possible quality. GPU Acceleration: Expedite video processing, even on older computers. How to get it Please ensure you read the terms and conditions to claim this offer. Complete and verifiable information is required in order to receive this free offer. If you have previously made use of these free offers, you will not need to re-register. While supplies last! Download VideoProc Converter AI V7.5 ($78.90 Value, now FREE) Offered by Digiarty, view other free resources The below offers are also available for free in exchange for your (work) email: Unruly: Fighting Back when Politics, AI, and Law Upend [...] ($18 Value) FREE - Expires 6/17 SQL Essentials For Dummies ($10 Value) FREE – Expires 6/17 Continuous Testing, Quality, Security, and Feedback ($27.99 Value) FREE – Expires 6/18 VideoProc Converter AI v7.5 for FREE (worth $78.90) – Expires 6/18 Macxvideo AI ($39.95 Value) Free for a Limited Time – Expires 6/22 The Ultimate Linux Newbie Guide – Featured Free content Python Notes for Professionals – Featured Free content Learn Linux in 5 Days – Featured Free content Quick Reference Guide for Cybersecurity – Featured Free content We post these because we earn commission on each lead so as not to rely solely on advertising, which many of our readers block. It all helps toward paying staff reporters, servers and hosting costs. Other ways to support Neowin The above deal not doing it for you, but still want to help? Check out the links below. Check out our partner software in the Neowin Store Buy a T-shirt at Neowin's Threadsquad Subscribe to Neowin - for $14 a year, or $28 a year for an ad-free experience Disclosure: An account at Neowin Deals is required to participate in any deals powered by our affiliate, StackCommerce. For a full description of StackCommerce's privacy guidelines, go here. Neowin benefits from shared revenue of each sale made through the branded deals site.
  • Recent Achievements

    • Week One Done
      fashionuae earned a badge
      Week One Done
    • One Month Later
      fashionuae earned a badge
      One Month Later
    • Week One Done
      elsafaacompany earned a badge
      Week One Done
    • Week One Done
      Yianis earned a badge
      Week One Done
    • Veteran
      Travesty went up a rank
      Veteran
  • Popular Contributors

    1. 1
      +primortal
      505
    2. 2
      ATLien_0
      262
    3. 3
      +FloatingFatMan
      191
    4. 4
      +Edouard
      175
    5. 5
      snowy owl
      126
  • Tell a friend

    Love Neowin? Tell a friend!