How to Add or Delete a Registy entry by Command Line Script

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_MACHINESOFTWAREPoliciesMicrosoftWindowsWindows 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>Scriptsdisable-cortana.reg"

HOW TO ADD A REGISTRY KEY USING COMMAND LINE SCRIPT

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 "HKLMSOFTWAREPoliciesMicrosoftWindowsWindows 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 .
/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 HKCUSoftwareSS64 /v Sample /d "some test data"
  • reg  add  HKEY_CURRENT_USEREnvironment  /v  userpath /t  REG_EXPAND_SZ  /d  C:Windows
  • REG ADD HKLMSoftwareMyCo /v Data /t REG_BINARY /d fe340ea
  • reg add HKLMSoftwaresav /v test /t REG_SZ /d ""%userprofile%""

HOW TO ADD 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 "HKLMSOFTWAREPoliciesMicrosoftWindowsWindows 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:

Leave a Reply

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