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

    • Generally, Earth never initiated that animals lay straight
    • Several UI improvements masquerading as a major update. I'm truly hating this trend.
    • OpenAI to use Google Cloud despite rivalry, diversifying beyond Microsoft by Paul Hill To help it meet its massive computing demands for training and deploying AI models, OpenAI is looking into a surprising partnership with Google Cloud to use its services. It was widely seen that OpenAI was Google’s biggest threat, but this deal puts an end to the idea that the pair are purely competing. The two companies haven’t made any public announcement about the deal but a source speaking to Reuters claimed that talks had been ongoing for a few months before a deal was finalized in May. Notably, such a deal would see OpenAI expand its compute sources beyond Microsoft Azure. Microsoft had arrangements in place with OpenAI since 2019 that gave it the exclusive right to build new computing infrastructure for the startup. This limitation was loosened earlier this year with the announcement of Project Stargate. OpenAI is now allowed to look elsewhere for compute if Microsoft is unable to meet the demand. A win for Google Cloud, a challenge for Google's AI strategy The deal will see Google Cloud supply computing capacity for OpenAI’s AI model training and inference. This is a big win for Google’s Cloud unit because OpenAI is a massive name in AI and it lends credence to Google’s cloud offering. It also justifies Google Cloud’s expansion of its Tensor Processing Units (TPUs) for external use. On the back of the news, Alphabet’s stock price rose 2.1%, while Microsoft’s sank 0.6%, showing investors think it’s a good move for Google too. While many end users don’t interact with Google Cloud the same way they do with something like Android or Chrome, Cloud is actually a huge part of Google’s business. In 2024, it comprised $43 billion (12%) of Alphabet’s total revenue. With OpenAI as a customer, this figure could rise even more given the massive amounts of compute OpenAI needs. By leveraging Google’s services, it will also give OpenAI access to the search giant’s Tensor Processing Units (TPUs). Unlike GPUs, these chips are specifically designed to handle the kinds of calculations that are most common in AI and machine learning, leading to greater efficiency. Google’s expansion of these chips to external customers has already helped it attract business from Anthropic and Safe Superintelligence. While Google will happily take OpenAI’s money, it needs to tread carefully giving compute power to a rival, which will only make OpenAI more of a threat to Google’s search business. Specifically, it’ll need to manage how resources are allocated between Google’s own AI projects and its cloud customers. Another issue is that Google has been struggling to keep up with the overall demand for cloud computing, even with its own TPUs, according to its Chief Financial Officer in April. By giving access to OpenAI, it means even more pressure. Hopefully, this will be short lived as companies compete to build out capacity to attract customers. OpenAI's push for compute independence Back in 2019 when Microsoft became OpenAI’s exclusive cloud partner in exchange for $1 billion, the AI landscape was much different. End users wouldn’t have access to ChatGPT for another 3 years and the rate of development of new models was less ferocious than it is today. As OpenAI’s compute needs evolve, its relationship with Microsoft has had to evolve too, including this deal with Google and the Stargate infrastructure program. Reuters said that OpenAI’s annualized run rate (the amount they’ll earn in one year at its current pace) had surged to $10 billion, which highlights its explosive growth and need for more resources than Microsoft alone can offer. To make itself more independent, OpenAI has also signed deals worth billions of dollars with CoreWeave, another cloud compute provider, and it is nearing the finalization of the design of its first in-house chip, which could reduce its dependency on external hardware providers altogether. Source: Reuters
    • I don't think that means what you think it means
    • The Google Home app gets video forwarding support and many more features by Aman Kumar Along with releasing the Android 16 update for supported Pixel devices, Google has also showcased a number of features coming to its Home app. First up is PiP, also known as picture-in-picture mode, which will be available for Nest Cams on any Google TV device you own. It’ll be similar to YouTube’s PiP, with which you must be familiar with. A small window will appear in a corner of the TV screen, allowing you to view your Nest Cams without interrupting your viewing experience. The feature is currently in public preview, and you can enroll to try it out before its public release. Another YouTube feature that Google is adding to its Home app is the ability to jump 10 seconds forward or backward in recorded videos. This feature ensures that you don't have to go through the entire footage to locate the moment you’re looking for. Google mentioned in its blog post that it is adding more controls to the Google Home web app. Currently, the web app offers limited functionality, such as setting automations and viewing cameras, but soon you’ll be able to manage more things through it, such as adjusting lighting, controlling temperature, and locking or unlocking the door. Google’s AI model, Gemini, is also getting more controls in the Home app. You can use natural language in the Gemini app to search for specific footage in the camera history. Furthermore, the fallback assistant experience that broadcast commands use is also being updated. You’ll now be able to use your voice to broadcast messages through the connected speakers in your home. The Google blog post also mentions that you are no longer required to use the standalone Nest app to receive smoke and other critical alerts. You can now view the Nest Protect smoke and carbon monoxide (CO) status directly in the Home app. You’ll also be able to run safety checkups and hush alarms through the Home app. In addition to all these features, Google is also making the automation creation process much quicker, will allow you to add more tiles to the Home app Favorites section, and will let you create different Favorites for any other device you use, such as your smartwatch. The Home app will now also support third-party Matter locks. Similar to the Nest x Yale lock, you’ll be able to control various settings of these third-party locks, like managing household access, creating guest profiles, and more.
  • Recent Achievements

    • Enthusiast
      computerdave91111 went up a rank
      Enthusiast
    • Week One Done
      Falisha Manpower earned a badge
      Week One Done
    • One Month Later
      elsa777 earned a badge
      One Month Later
    • Week One Done
      elsa777 earned a badge
      Week One Done
    • First Post
      K Dorman earned a badge
      First Post
  • Popular Contributors

    1. 1
      +primortal
      535
    2. 2
      ATLien_0
      272
    3. 3
      +FloatingFatMan
      201
    4. 4
      +Edouard
      200
    5. 5
      snowy owl
      138
  • Tell a friend

    Love Neowin? Tell a friend!