6

This registry script writes a REG_NONE empty 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

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

I need to reproduce the same in Batch (to improve a 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 the REG_NONE valuetype? (the command help says its a supported value but... you see)

How I could really add a REG_NONE empty value?

ElektroStudios
  • 19,105
  • 33
  • 200
  • 417
  • 1
    In my opinion it is a design error in code (bug) of **REG** to support type *REG_NONE*, but adding a value of this type with `00 00` (terminating null of a Unicode string) even if `/D "..."` is not specified on command line. `REG ADD "HKCU\Key Name" /V "Value Name" /T REG_NONE /F` should do the job, but definitely does not which could be interpreted as bug of **REG** worth being reported to Microsoft. – Mofi Aug 24 '14 at 18:08
  • @Mofi thanks for comment, I've tested the same command in Windows XP and the resulting value is the same null string: '00 00', do you know the link to report a possible bug to Microsoft? – ElektroStudios Aug 25 '14 at 02:04
  • 1
    Reporting bugs in Windows and its installed tools is very difficult as it can be read on [Where can I report a bug in Windows 7?](http://social.technet.microsoft.com/Forums/windows/en-US/f47faf0a-438a-42d7-9fd5-cd6e373f0da5) and [How to report a bug in Windows 7?](http://answers.microsoft.com/en-us/windows/forum/windows_7-performance/how-to-report-a-bug-in-windows-7/58040738-af09-4ea6-830e-72ddd4e9b4e2) There is more or less no other method than contacting Microsoft support by phone to report things like this and hope that person of Microsoft support interprets it also as an issue to process. – Mofi Aug 25 '14 at 06:07

2 Answers2

6

The only nasty option I found so far is creating a .reg file and import that one:

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 (the commandline tools are optimized for String and multi string) can only be created with a zero-length binary value by the RegSetValueEx windows api. The higherlevel api's like the one on the WMI provider only allow for SetBinaryValue and there is no SetNoneValue. Beside REG there is also an option to use wmic that sits a little bit closer on the WMI provider but that still doesn't allow you to create a REG_NONE type (it does enable you to create zero-length REG_BINARY, something REG is also unable to do)

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

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

is a two zero bytes: 00 00, caused by the two null character termination from (the not provided with the option /d ) multi String

Community
  • 1
  • 1
KennyBOT
  • 449
  • 3
  • 12
  • While i can not disagree with the core (the only way to solve the problem is to use a reg file), it is not correct to say that a REG_NONE can only be created with RegSetValueEx (the OP created it with `reg.exe`), and it is not correct to say `reg.exe` can not create a empty binary value: `reg add "hkcu\volatile environment" /v test /t reg_binary`. The problem with `reg.exe` is that when the type is reg_none, it reads the command line to retrieve a reg_multi_sz value, the reason for the 0x00 0x00 value, a double null terminated string. – MC ND Aug 25 '14 at 05:39
  • You can embed the reg file in the batch somewhat as [Rob van der Woude](http://www.robvanderwoude.com/regedit.php#SelfContained) posted. – Ir Relevant Aug 25 '14 at 18:14
  • @IrRelevant That is an interesting trick but I don't think it can be applied here because the reg file is not static. – KennyBOT Aug 25 '14 at 19:09
1

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

Usage:

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

Oh and guys don't forget to try my application and report me bugs (if any) :)

enter image description here

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

ElektroStudios
  • 19,105
  • 33
  • 200
  • 417