How to search and delete in registry a single REG_SZ value
Solution 1
You can't delete just a part of the value of a key using a batch script.
You can delete LM_LICENSE_FILE
, which is a REG_SZ
, but I don't think that's what you want.
You could use reg add
to achieve what you're asking, though:
reg add "HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Environment" /f /v "LM_LICENSE_KEY" /t REG_SZ /d "123@abc;123@fgh"
will overwrite your existing LM_LICENSE_FILE
variable with the new value of 123@abc;123fgh
.
- -
reg add "HKLM\...\Environment"
command, key -
/f /v "LM_LICENSE_KEY
overwrite without prompting, value to act on -
/t REG_SZ
datatype to add (default isREG_SZ
so you could actually omit it here) -
/d "123@abc;123@fgh"
data to be added
Solution 2
How do I search for and delete a REG_SZ value in System environment variables?
You can use reg
to both find and delete registry entries.
You will need to know in which root the registry item you want to delete is stored.
Read, Set or Delete registry keys and values, save and restore from a .REG file.
Syntax:
...
REG DELETE [ROOT]RegKey /v ValueName [/f]
REG DELETE [ROOT]RegKey /ve [/f] -- Remove the (default) value
REG DELETE [ROOT]RegKey /va [/f] -- Delete all values under this key
...
Key:
ROOT :
HKLM = HKey_Local_machine (default)
HKCU = HKey_current_user
HKU = HKey_users
HKCR = HKey_classes_root
...
ValueName : The value, under the selected RegKey, to edit. (default is all keys and values)
Source reg.exe
Warning
The instructions above contain steps that tell you how to modify the registry.
However, serious problems might occur if you modify the registry incorrectly.
For added protection, back up the registry before you modify it. Then, you can restore the registry if a problem occurs.
For more information see How to back up and restore the registry in Windows.
Further Reading
- An A-Z Index of the Windows CMD command line - An excellent reference for all things Windows cmd line related.
- reg - Read, Set or Delete registry keys and values, save and restore from a .REG file.
Related videos on Youtube
Sync
Updated on September 18, 2022Comments
-
Sync over 1 year
How do I search an delete a
REG_SZ
value in System environment variables. For example, in System variables I have Variable namedLM_LICENSE_FILE= 123@abc;123@cde;123@fgh
I want to have a script to search for
123@cde
and delete it.