Breaking News

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_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

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.
/veSpecifies 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.
/fAdds 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 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.
/veSpecifies that only entries that have no value will be deleted.
/vaDeletes all entries under the specified subkey. Subkeys under the specified subkey are not deleted.
/fDeletes 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:

No comments