How to add empty REG_NONE value using Batch?

This registry script writes an empty REG_NONE value in the reg editor (which is represented as binary data):

 Windows Registry Editor Version 5.00 [HKEY_CURRENT_USER\keyname] "valuename"=hex(0): 

enter image description here

(English translation of the description of the data in the image above: "binary value of zero length")

I need to reproduce the same in Batch (to improve the Reg2Bat converter), but when I try this:

 REG ADD "HKCU\keyname" /V "valuename" /T "REG_NONE" /D "" /F 

It adds data:

enter image description here

Maybe the reg.exe command is not compatible with valuetype? (the help command talks about a supported value, but ... you see)

How can I really add an empty REG_NONE value?

+5
source share
2 answers

The only nasty option I've found so far is to create a REG file and import it:

 call :regnone HKEY_CURRENT_USER "keyname" valuename goto :eof :regnone rem create a reg file echo Windows Registry Editor Version 5.00 > none.reg echo [%~1\%~2] >> none.reg echo "%~3"=hex(0): >> none.reg rem import it the registry reg import none.reg del /q none.reg goto :eof 

REG_NONE is a special type that, due to implementation details (command line tools are optimized for String and multi string) can only be created with a binary value of zero length using the RegSetValueEx windows api. A higher level api, such as the one on the WMI provider, allows SetBinaryValue and no SetNoneValue . Besides REG there is also the possibility to use wmic, which comes a little closer to the WMI provider, but it still does not allow you to create the REG_NONE type (it allows you to create REG_BINARY with zero length, that is, REG also cannot)

The closest null binary value you can get with this command (provided by MC ND )

 reg add "hkcu\volatile environment" /v test /t reg_binary 

are two null bytes: 00 00 caused by two null character terminations (not provided with the /d option) multi String

+4
source

Just my extended solution based on @KennyBOT answer:

 :Add_Special_Value :: Support for adding an special registry value type. Set "KeyRoot=%~1" Set "KeyName=%~2" Set "ValueName=%~3" Set "ValueType=%~4" Set "ValueData=%~5" Set "RegFile=%TEMP%\%ValueType%.reg" If /I "%KeyRoot%" EQU "HKCR" (Set "KeyRoot=HKEY_CLASSES_ROOT") If /I "%KeyRoot%" EQU "HKCU" (Set "KeyRoot=HKEY_CURRENT_USER") If /I "%KeyRoot%" EQU "HKLM" (Set "KeyRoot=HKEY_LOCAL_MACHINE") If /I "%KeyRoot%" EQU "HKCC" (Set "KeyRoot=HKEY_CURRENT_CONFIG") If /I "%KeyRoot%" EQU "HKU" (Set "KeyRoot=HKEY_USERS") If /I "%ValueType%" EQU "REG_NONE" (Set "ValueType=hex^(0^)") If /I "%ValueType%" EQU "REG_RESOURCE_LIST" (Set "ValueType=hex^(8^)") If /I "%ValueType%" EQU "REG_RESOURCE_REQUIREMENTS_LIST" (Set "ValueType=hex^(a^)") If /I "%ValueType%" EQU "REG_FULL_RESOURCE_DESCRIPTOR" (Set "ValueType=hex^(9^)") ( Echo Windows Registry Editor Version 5.00 Echo [%KeyRoot%\%KeyName%] Echo "%ValueName%"=%ValueType%:%ValueData% )>"%RegFile%" REG.exe "Import" "%RegFile%" DEL /Q "%RegFile%" 2>NUL Goto :EOF 

Using:

 Call :Add_Special_Value "HKCU" "MyKeyName" "MyValueName" "REG_NONE" "Binary data (If any)" 

Oh guys, don't forget to try my app and let me know about errors (if any) :)

enter image description here

SOURCE CODE (VB.NET): http://www.mediafire.com/download/1h3zbymfhnb3spt/REG2BAT.rar

+1
source

Source: https://habr.com/ru/post/1200785/


All Articles