The registry is the place where most of the applications store the settings but not only. Used also from the windows system to store important settings in order to be available to operate. We will cover a series of articles to explain how can be added, edited, and deleted the registry keys and values. This will be done using the Windows command prompt but not only. Will try to use also the PowerShell and GPO. In the end, you will be available to change them individually or over the network using batch. In this part, we will cover how to add registry key and values with command line, PowerShell, and batch file.
Check Also:
How to Edit Registry Key/value
How to Delete Registry Key/value
How to add registry key and value with CMD:
Below is the default commands line to add new registry key and “NewTestKey” on path “HKEY_CURRENT_USER\Software\” – To run it:
- Start
- Search “CMD”
- Run as Administrator
- Execute Below Command
reg add HKEY_CURRENT_USER\Software\NewTestKey
Below is the default command to add new registry value entry “TestValue” of type “DWORD (32-bit)” on path “HKEY_CURRENT_USER\Software\NewTestKey\” and add the value of “1”. To run it:
- Start
- Search “CMD”
- Run as Administrator
- Execute Below Command
Customized:
reg add HKEY_CURRENT_USER\Software\NewTestKey\ /v TestValue /t REG_DWORD /d 1
Default Command:
Reg Add Regkey /v RegValue /t RegType /d data
Command Description:
- Regkey – Path where the new value should be added.
- RegValue – Name of the value that should be added
- /t – Type of the value (REG_SZ, REG_DWORD, REG_BINARY)
- /d Data – Specifies the data for the new entry in the registry.
How to add Registry key and value with PowerShell:
Below is the PowerShell default command to add new registry key “NewTestKey” on path “HKEY_CURRENT_USER\Software\” – To run it:
- Start
- Search PowerShell
- Run as Administrator
- Execute Below Command
# Set the location to the registry Set-Location -Path 'HKCU:\Software\' # Create a new Key Get-Item -Path 'HKCU:\Software\' | New-Item -Name 'NewTestKey' –Force
Below is the PowerShell default command to add new registry value entry “TestValue” of type “DWORD (32-bit)” on the path “HKEY_CURRENT_USER\Software\NewTestKey\” and add the value of “1” – To run it:
- Start
- Search PowerShell
- Run as Administrator
- Execute Below Command
# Create new items with values New-ItemProperty -Path 'HKCU:\Software\NewTestKey' -Name 'TestValue' -Value '1' -PropertyType 'DWORD' –Force # Get out of the Registry Pop-Location
How to add Registry key and value on a remote computer:
Below is the command to add registry key on a remote computer. To run it:
- Start
- Search “CMD”
- Run as Administrator
- Execute Below Command
REG ADD \\ComputerName\HKCU\Software\NewTestKey
Below is the command to add registry value on a remote computer. To run it:
- Start
- Search “CMD”
- Run as Administrator
- Execute Below Command
REG ADD \\ComputerName\HKCU\Software\NewTestKey /v TestValue /t REG_DWORD /d 1
How to add registry key and value with batch file:
The same commands used above to add the registry key from the command prompt can be integrated on the batch file. The commands can be used on the existing batch along with other commands or on the new batch file. To create a new batch file:
- Open a notepad files
- Write the below command
@echo off reg add HKEY_CURRENT_USER\Software\NewTestKey reg add HKEY_CURRENT_USER\Software\NewTestKey\ /v TestValue /t REG_DWORD /d 1
- Save it as regedit.bat
- Run it with DoubleClick and the command will be executed.
The bat files used mostly when you want to spread it over the network using GPO or SCCM
How to add registry key and value with regedit file (.reg)
You can add registry key and value by using .reg file. This file structure can be found by exporting certain keys from the regedit interface by right-clicking on it and the export option. To create it from the screech:
- Open a notepad file
- Copy and paste the below command
Windows Registry Editor Version 5.00 [HKEY_CURRENT_USER\Software\NewTestKey2]
- Save it at addkey.reg
This command with creates NewTestKey2 key if does not exist. To add registry value copy and paste the following command:
Windows Registry Editor Version 5.00 [HKEY_CURRENT_USER\Software\NewTestKey2] @="HKEY_CURRENT_USER\\Software" "TestValue"=dword:00000001
The command with creating new value “TestValue” of type dword with value “1”. To execute .reg files, double-click it and after typing to the confirmation yes the changes with be done.
Conclusion:
Those are the methods to add registry key and values using command prompt, PowerShell, and batch files. Follow us for the next articles where we will explain the methods to edit and delete keys and values from the registry