windows REG 添加一个 REG_MULTI_SZ 多行注册表值

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/8853911/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 09:06:43  来源:igfitidea点击:

REG ADD a REG_MULTI_SZ Multi-Line Registry Value

windowscommand-lineregistry

提问by Edwin Lee

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

要添加 REG_MULTI_SZ 多行注册表值,我可以

reg.exe ADD "HKLM\path\to\registry\key" /v RegistryValue /t REG_MULTI_SZ /d "abc
reg.exe ADD "HKLM\path\to\registry\key" /v RegistryValue /t REG_MULTI_SZ /d "abc
REG ADD "HKLM\LOCATION" /v "Value" /t REG_MULTI_SZ /d item1
REG ADD "HKLM\LOCATION" /v "Value" /t REG_MULTI_SZ /d "item1"
REG ADD "HKLM\LOCATION" /v "Value" /t REG_MULTI_SZ /d item1
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
item2
@reg.exe add "HKCU\Software\Wirkomatron" /v "MySoftware" /d "Software1"##代码##"Software2"##代码##"Software3"##代码## /t REG_MULTI_SZ /f
##代码## /f
"item2" /f
item2 /f
##代码##def##代码##"
def##代码##"

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

这将添加(“abc”,“def”)。

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

但是如果我需要添加 ("abc", "", "def"),即中间的一个空项怎么办?

Doing

正在做

##代码##

gives me an "invalid parameter" error.

给我一个“无效参数”错误。

回答by seth

This worked for me:

这对我有用:

##代码##

or if your items have whitespace:

或者如果您的项目有空格:

##代码##

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'.":

确保您没有两个尾随“\0”分隔符(一个都可以,无论是否带有尾随 \0,您都将获得最后一个返回字符),如下例所示(就像我在 TechNet 文章中看到的那样),或者您将得到一个“错误:为‘/d’指定的无效值。”:

##代码##

回答by Harry Johnston

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.

这可能无法使用 reg add,因为您尝试设置的数据格式不正确。REG_MULTI_SZ 值以空字符串终止,因此不允许将空字符串作为值的一部分。

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:

如果您确实需要,并且了解某些软件将无法正确读取密钥,则可以改用 reg import。例如,以下文件创建了一个中间带有空字符串的值:

##代码##

回答by RizonBarns

Try this:

尝试这个:

##代码##

And now you can do it with Batch script propertly.

现在您可以使用批处理脚本正确地做到这一点。

回答by JeffreyPaesch

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"

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