如何从命令行向注册表添加多行REG_SZ字符串? [英] How do I add a multiline REG_SZ string to the registry from the command line?
问题描述
作为Windows机器上的构建设置的一部分,我需要添加一个注册表项,并且我想从一个简单的批处理文件中完成此操作.
As part of a build setup on a windows machine I need to add a registry entry and I'd like to do it from a simple batch file.
该条目用于第三方应用程序,因此格式是固定的.
The entry is for a third party app so the format is fixed.
该条目采用REG_SZ字符串的形式,但需要包含换行符. 0xOA字符作为分隔符.
The entry takes the form of a REG_SZ string but needs to contain newlines ie. 0xOA characters as separators.
我遇到了一些问题.
首次尝试使用regedit加载生成的.reg文件.这失败了,因为它似乎既不喜欢长字符串也不喜欢带换行符的字符串.我发现导出工作正常,导入失败.我能够测试导出,因为第三方应用程序直接通过win32 api添加了类似的条目.
First attempt used regedit to load a generated .reg file. This failed as it did not seem to like either either long strings or strings with newlines. I discovered that export works fine import fails. I was able to test export as the third party app adds similar entries directly through the win32 api.
第二次尝试使用了REG ADD命令,但是无论如何我都找不到添加换行字符的所有尝试,但最终都添加了一个文字字符串.
Second attempt used the command REG ADD but I can't find anyway to add the newline characters everything I try just ends up with a literal string being added.
推荐答案
您可以创建一个VBScript(.vbs)文件并仅从一个批处理文件中调用它,前提是您要在此注册表中执行其他操作改变.在vbscript中,您将看到以下内容:
You could create a VBScript(.vbs) file and just call it from a batch file, assuming you're doing other things in the batch other than this registry change. In vbscript you would be looking at something like:
set WSHShell = CreateObject("WScript.Shell")
WSHShell.RegWrite "HKEY_LOCAL_MACHINE\SOMEKEY", "value", "type"
您应该可以使用Google查找可能的类型值.
You should be able to find the possible type values using Google.
这篇关于如何从命令行向注册表添加多行REG_SZ字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!