5

To add a REG_MULTI_SZ multi-line registry value, i can do

reg.exe ADD "HKLM\path\to\registry\key" /v RegistryValue /t REG_MULTI_SZ /d "abc\0def\0"

which would add ("abc", "def").

But what if i need to add ("abc", "", "def"), i.e. an empty item in between?

Doing

reg.exe ADD "HKLM\path\to\registry\key" /v RegistryValue /t REG_MULTI_SZ /d "abc\0\0def\0"

gives me an "invalid parameter" error.

Edwin Lee
  • 3,540
  • 6
  • 29
  • 36
  • My question was different but the answer might help, see: http://stackoverflow.com/questions/153879/how-do-i-add-a-multline-reg-sz-string-to-the-registry-from-the-command-line – morechilli Jan 13 '12 at 17:43

4 Answers4

10

This worked for me:

REG ADD "HKLM\LOCATION" /v "Value" /t REG_MULTI_SZ /d item1\0item2 /f

or if your items have whitespace:

REG ADD "HKLM\LOCATION" /v "Value" /t REG_MULTI_SZ /d "item1"\0"item2" /f

Make sure you don't have TWO trailing "\0" separators (one is OK, with or without the trailing \0 you will get your last return character) like the example below (like I saw in a TechNet article), or you will get an "ERROR: Invalid value specified for '/d'.":

REG ADD "HKLM\LOCATION" /v "Value" /t REG_MULTI_SZ /d item1\0item2\0\0 /f
seth
  • 101
  • 1
  • 2
7

This probably isn't possible using reg add, because the data you're trying to set is improperly formed. REG_MULTI_SZ values are terminated by an empty string, so having an empty string as part of the value is not allowed.

If you really need to, and on the understanding that some software won't be able to read the key correctly, you could use reg import instead. For example, the following file creates a value with an empty string in the middle:

Windows Registry Editor Version 5.00

[HKEY_CURRENT_USER\software\harrytest]
"test"=hex(7):76,00,61,00,6c,00,75,00,65,00,31,00,00,00,76,00,61,00,6c,00,75,\
  00,65,00,32,00,00,00,00,00,76,00,61,00,6c,00,75,00,65,00,34,00,00,00,76,00,\
  61,00,6c,00,75,00,65,00,35,00,00,00,00,00
Harry Johnston
  • 35,639
  • 6
  • 68
  • 158
  • thanks, this works for me. but what do you mean by "on the understanding that some software won't be able to read the key correctly"? is that something i'll have to watch out for? – Edwin Lee Jan 16 '12 at 16:11
  • It depends on the context. Presumably there's some particular piece of software that is going to be reading the data you put in this key, so all that really matters is whether that software can cope. – Harry Johnston Jan 16 '12 at 20:04
  • I tried reg import for a REG_MULTI_SZ and it does not seem to be working. As an FYI, reg export did not work for this key either. Any ideas what might be going on? – Saltz3 Sep 01 '17 at 17:03
2

Try this:

@reg.exe add "HKCU\Software\Wirkomatron" /v "MySoftware" /d "Software1"\0"Software2"\0"Software3"\0 /t REG_MULTI_SZ /f

And now you can do it with Batch script propertly.

Perception
  • 79,279
  • 19
  • 185
  • 195
RizonBarns
  • 21
  • 1
1

Just for reference.

If you just want to insert a new line then you will need to simulate it with a space in the desire empty line. If the space would have an undesired impact in what you are trying to achieve then this post is not useful for you.

reg.exe ADD "HKLM\path\to\registry\key" /v RegistryValue /t REG_MULTI_SZ /d "abc\0 \0def\0"