If you need to add a registry entry to a Windows PC most often techs will simply export the key and entries they want and then use the REGEDIT /S command to push that entry onto another PC.

For example if you want to disable the Cortana bar (but not Windows Search), you save the following into a file named DISABLE-CORTANA.REG

Windows Registry Editor Version 5.00

[HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Microsoft\Windows\Windows Search]
"AllowCortana"=dword:00000000

Then you simply put that file on one of your servers and push it out to your PC’s using something like:

regedit /s "\\<Your-Server>\<Your-Share>\Scripts\disable-cortana.reg"

HOW TO ADD A REGISTRY KEY USING COMMAND LINE SCRIPT:

reg-add-delete-copy-cmd-line-scriptHowever, if you have a simple registry change you want to make you can avoid the .REG file and simply use REG ADD command to make your change.  For instance:

reg add "HKLM\SOFTWARE\Policies\Microsoft\Windows\Windows Search" /v AllowCortana /t REG_DWORD /d 1 /f

The switches mean:

/v <ValueName> Specifies the name of the registry entry to be added under the specified subkey.
/ve Specifies that the registry entry that is added to the registry has a null value.
/t <Type> Specifies the type for the registry entry. Type must be one of the following:
REG_SZ
REG_MULTI_SZ
REG_DWORD_BIG_ENDIAN
REG_DWORD
REG_BINARY
REG_DWORD_LITTLE_ENDIAN
REG_LINK
REG_FULL_RESOURCE_DESCRIPTOR
REG_EXPAND_SZ
/s <Separator> Specifies the character to be used to separate multiple instances of data when the REG_MULTI_SZ data type is specified and more than one entry needs to be listed. If not specified, the default separator is \0.
/d <Data> Specifies the data for the new registry entry.
/f Adds the registry entry without prompting for confirmation.
Here are some more examples you may find useful:
  • REG ADD HKCU\Software\SS64 /v Sample /d "some test data"
  • reg  add  HKEY_CURRENT_USER\Environment  /v  userpath /t  REG_EXPAND_SZ  /d  C:\Windows
  • REG ADD HKLM\Software\MyCo /v Data /t REG_BINARY /d fe340ea
  • reg add HKLM\Software\sav /v test /t REG_SZ /d "\"%userprofile%\""

HOW TO DELETE A REGISTRY KEY USING COMMAND LINE SCRIPT:

Deleting a registry key using command line is simple, using the syntax:
Reg delete <KeyName> [{/v ValueName | /ve | /va}] [/f]
The switches for REG DELETE are:
<KeyName> Specifies the full path of the subkey or entry to be deleted. To specify a remote computer, include the computer name (in the format \\ComputerName) as part of the KeyName. Omitting \\ComputerName\ causes the operation to default to the local computer. The KeyName must include a valid root key. Valid root keys for the local computer are: HKLM, HKCU, HKCR, HKU, and HKCC. If a remote computer is specified, valid root keys are: HKLM and HKU.
/v <ValueName> Deletes a specific entry under the subkey. If no entry is specified, then all entries and subkeys under the subkey will be deleted.
/ve Specifies that only entries that have no value will be deleted.
/va Deletes all entries under the specified subkey. Subkeys under the specified subkey are not deleted.
/f Deletes the existing registry subkey or entry without asking for confirmation.
For example:
reg delete "HKLM\SOFTWARE\Policies\Microsoft\Windows\Windows Search" /f

DETAILS ON ALL THE REG COMMANDS:

Here are all of the REG commands in Windows 10, with links to their respective Microsoft support pages:

2 Comments

Sunny · November 4, 2020 at 11:45 am

Reg query and reg del to be use in script
http://winplat.in/2020/10/26/using-reg-command-line-tool-for-registry-operation/

Joseph Peni · June 21, 2019 at 4:04 pm

After years of searching for a way to easily delete registry entries – I discovered RegScanner.

RegScanner by NirSoft is a small free utility that allows you to scan the Registry, find the desired Registry values that match to the specified search criteria, and display them in one list.

One of the best features of RegScanner is the ability to search for a keyword or value and create a REG file from the resulting list.

This comes in handy when you have multiple registry entries that refuse to delete. Many stubborn registry entries will delete when you create a REG file and replace all [HKEY values with [-HKEY before executing

Leave a Reply

Avatar placeholder

Your email address will not be published. Required fields are marked *