What command allows you to view registry keys and values and import and export some or all of a registry?

Windows users can access and edit the Windows registry through the command line. Review the sections below for the version of Windows on your computer and information about registry edit commands and syntax.

Tip

If you're attempting to edit the registry from the command line because you're unable to get to normal Windows, try first booting to Windows Safe Mode. Then, run Regedit from Safe Mode.

Tip

To open Windows registry in the command prompt, press Windows key+R, type cmd, and press Enter. In the Command Prompt, type regedit and press Enter.

Microsoft Windows XP, Vista, 7, 8, 10, and 11 users

What command allows you to view registry keys and values and import and export some or all of a registry?

Microsoft Windows XP and later users can view, edit, and modify their registry from the Command Prompt application using the reg command. See the reg command page for additional information and examples.

Microsoft Windows 95, 98, ME, and 2000 users

Note

The instructions in this section also work for later versions of Microsoft Windows.

By default, Microsoft Windows 95, 98, ME, and 2000 users can import registry files from the command prompt using the Regedit command. Using this command and a registry file containing the proper commands, a user can add, remove, and otherwise edit the registry from the command line.

If you want to import a registry file from the command line, you can use the Regedit command and the name of the file you want to import. For example, if the name of the file was hope.reg, type the following command.

Regedit hope.reg

The file hope.reg could contain the commands necessary to add and remove registry values. Below are examples of registry files to create entries, delete single entries, and a complete folder. To create these files yourself, copy the following examples into an empty .reg file or use notepad or the edit command to create a file using the following commands.

Note

Users running earlier versions of Windows may want to substitute Windows Registry Editor Version 5.00 with REGEDIT4.

The following example adds a ComputerHope folder into the HKEY_LOCAL_MACHINE\Software directory with a string example and data value of data here.

Windows Registry Editor Version 5.00
[HKEY_LOCAL_MACHINE\SOFTWARE\ComputerHope]
"example"="data here"

To delete a single entry in the registry, add a hyphen (minus) key after the equal sign. For example, if we wanted to delete our string value "example" we created with the above example, we would create the following .reg file.

The Windows registry is a database that contains important, machine-specific settings and information regarding almost everything in your computer — preferences, applications, users, attached devices and so on. The registry contains two basic elements: keys and values. The Windows operating system is constantly referring to the registry; for example, to open a program, install new software or change your hardware, Windows must check the values of certain keys.

A registry file can become corrupted due to malware or issues, which can lead to poor performance or even the operating system crashing. To ensure you can recover from corruption, you should back up your  reg files regularly. So let’s find out how to make an entire registry backup and restore the registry in Windows.

Handpicked related content:

  • Windows Server 2016 Security eBook 

Making a Windows Registry Backup

Back up the Windows Registry Using Regedit

Back up your registry regularly, and also before you attempt to change, create or remove registry settings or hives, or install new system drivers, so you can revert to a known good version if something goes wrong. Follow these steps to create a backup:

  1. Press the Windows button and the R button simultaneously to open the Run window.
  2. Type “regedit” to open the registry editor and press Enter.
  3. Click File > Export.
  4. In the dialogue box, enter a name for the backup file (for example “rgbkp2018”), select the location where you want to export registry file and click Save to create and save the backup.

What command allows you to view registry keys and values and import and export some or all of a registry?

Backing up the Windows Registry Using the Command Prompt

You can export registry records by typing reg export and a particular registry root key at the command prompt. To export multiple keys, you can use a script like the following:

reg export HKCR C:\RegBack\HKCR.Reg /y

reg export HKCU C:\RegBack\HKCU.Reg /y

reg export HKLM C:\RegBack\HKLM.Reg /y

reg export HKU C:\RegBack\HKU.Reg /y

reg export HKCC C:\RegBackHKCC.Reg /y

You can also back up your registry automatically with third-party registry cleaning software like CCleaner Registry Cleaner; you can find more about top free tools in the article “How to Perform Windows Registry Repair.”

Restoring the Windows Registry

You can restore your registry in several different ways. Here are the most common methods:

  • From Safe Mode
  • From the command prompt
  • Using System Restore
  • Using Automatic Repair
  • Using System File Checker
  • By resetting the PC
  • Using the DISM command
  • By reinstalling Windows from scratch

How to Restore a Registry Backup from Safe Mode

This is the most basic method. First, boot Windows in Safe Mode by pressing the F8 button while turning your computer on. When you boot in Safe Mode, Windows loads a minimal environment that helps ensure a stable system and protect vital files and drivers from corruption. Once you’ve booted into Safe Mode, perform the following commands:

  1. Press the Windows button and the R button simultaneously to open the Run window.
  2. Type “regedit” and press Enter.
  3. Click File > Import to import a registry file.
  4. In the Import Registry dialogue box, browse to the location where you saved the file of your backup and click Open.

What command allows you to view registry keys and values and import and export some or all of a registry?

Alternatively, a slightly quicker method is to browse to the location with the backup, right-click the file and select Merge. The file will be automatically imported to your registry.

What command allows you to view registry keys and values and import and export some or all of a registry?

How to Restore the Registry from the Command Prompt

In some situations, the Windows system will not boot into Safe Mode, so you need to manually restore your registry from the command prompt. To do this, you’ll need your original Windows OS disk or an ISO image on the bootable flash drive with your Windows operating system.

Tap the F8 button before Windows starts and choose Repair My Computer. If F8 doesn’t work, boot from your CD or flash drive by selecting your CD-ROM or flash drive as a primary bootable device in the BIOS and enter the repair Windows mode from there. After booting the Windows OS setup, go to System Recovery and select the command prompt.

We’ll be assuming your Windows directory is located on the C drive. Enter these commands to change your working directory to the directory with your backup:

Cd /d C:\windows\System32\config

xcopy *.* C:\RegBack\

cd RegBack

dir

Then replace the current registry settings with the ones from the backup using these commands:

copy /y software ..

copy /y system ..

copy /y sam ..

Note that the two periods are part of the command.

After this process completes, restart your computer.

How to Restore the Windows Registry with System Restore

You can also restore your computer’s registry using a Windows system restore point. If your computer has System Restore enabled, restore points will be created automatically when major changes are made to the system, such as the installation of new drivers. You can also create restore points manually.

  1. To open the System Restore window, click the Start menu and enter “restore” in the search box.
  2. Select System Restore from the list of results.
  3. Select a restore point. Windows will select the most recent restore point. If the registry corruption has been around for a while, click Show more restore points to see earlier ones. Each restore point will have a timestamp as well as a brief description of why the restore point was created.
  4. Click Scan for affected programs to see all of the programs and drivers that will be deleted from the computer and all programs that will likely not work correctly if you proceed with the restore. A system restore will not affect any of your personal files.
  5. Click Next and then Finish to start the restore process. This may take a few minutes. Your computer will reboot after the restore is complete.

How to Restore the Registry with Automatic Repair

Newer versions of Microsoft Windows, starting from Windows XP, include an automatic repair feature. When you run Automatic Repair, it will attempt to fix corrupt registry keys and repair invalid keys. In Windows 10, take these steps (note that in Windows XP, Windows Vista and Windows 7, the steps might be different):

  1. Open the Settings
  2. Go to the Update & Security section and click
  3. On the Advanced Startup panel, click Restart now.
  4. After the computer reboots, on the Choose an option screen, click Troubleshoot.
  5. On the Advanced Options screen, click Automated Repair.
  6. Choose an account and log in when prompted to do so.
  7. Automatic repair will start. Your computer might reboot during this process.

How to Restore the Registry with System File Checker

Another way to fix a corrupted registry is to run the System File Checker:

  1. Run cmd.exe with administrator rights.
  2. In the command window, type “sfc /scannow” and press Enter.
  3. Wait until the scan is complete and then reboot if needed.

How to Restore the Registry by Resetting the PC

Windows 10 allows you to reset your computer and leave all your files untouched. This option completely refreshes your system files and may help with restoring the registry after a system crash. Here are the steps to follow:

  1. Go to Settings and click Update and Security.
  2. Select
  3. In the Reset This PC section, click Get Started and then click Keep My Files.
  4. Click Next twice and then click Finish.

Perform a Registry Restore with the DISM Command

  1. Run cmd.exe with administrator rights.
  2. Run the following command: DISM /Online /Cleanup-Image /ScanHealth
  3. Wait until the scan process completes.

Reinstalling Windows from Scratch

If these methods didn’t fix your registry problems, then you probably will have to reinstall Windows from scratch, which will reset the registry to factory settings.

Conclusion

You should back up your registry on a regular schedule and before any major change so you can restore it if the installation of a program, driver or device causes issues. It is also important to track changes to your registry entries to quickly spot registry corruption. In particular, malware often changes registry startup keys so it will start automatically after each reboot. You can learn more about tracking Windows Server registry changes in this guide about detecting modifications to startup items in the Windows registry.

Handpicked related content:

  • How to Get, Edit, Create and Delete Registry Keys with PowerShell

  • How to Perform Windows Registry Repair and Fix Errors (+Top 7 Free Registry Cleaners)

  • Top 10 Best Windows Server Monitoring Software Tools

What command allows you to view registry keys and values and import and export some or all of a registry?

Jeff Melnick

Jeff is a former Director of Global Solutions Engineering at Netwrix. He is a long-time Netwrix blogger, speaker, and presenter. In the Netwrix blog, Jeff shares lifehacks, tips and tricks that can dramatically improve your system administration experience.

How to export registry key from command line?

Type “regedit” to open the registry editor and press Enter. Click File > Export. In the dialogue box, enter a name for the backup file (for example “rgbkp2018”), select the location where you want to export registry file and click Save to create and save the backup.

Which command can be used to export a registry key from a running machine?

For example, typing: Regedit /e full. reg would export the full registry to the full. reg file. This switch can also be used to export individual registry keys.

What is the command to open the registry from a command prompt?

Press Windows + R, type cmd and hit Enter to open Command Prompt on Windows 10. Then you can type regedit in Command Prompt window to open Registry Editor.

Which command is used to access the registry?

Right-click Start , then select Run. Type regedit in the Open: box, and then select OK.