windows 如何使用 WshShell.RegRead 读取名称为文件路径的注册表值
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/454781/
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
How to read a registry value whose name is a file path using WshShell.RegRead
提问by Brian Rogers
I am writing some javascript to be executed by the Windows Scripting Host, and I need to be able to read the shared file counts from the registry for certain specific DLLs. The registry key and values look like this:
我正在编写一些由 Windows 脚本主机执行的 javascript,我需要能够从注册表中读取某些特定 DLL 的共享文件计数。注册表项和值如下所示:
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\SharedDlls] "C:\Program Files\Common Files\ACME Corp\AcmeUtil.dll"=dword:00000002 "C:\Program Files\Common Files\ACME Corp\SuperEdit.ocx"=dword:00000001
I am attempting to use the WshShell.RegReadmethod to do this, but it doesn't seem to work. I think the problem is that this method only takes a single parameter which is the concatenated key path and value name for the value to be retrieved. Since the value name in this case is itself a path, the method thinks it is part of the key. Is there any way to get this method to recognize the value name for what it is?
我正在尝试使用WshShell.RegRead方法来执行此操作,但它似乎不起作用。我认为问题在于这个方法只需要一个参数,它是要检索的值的连接键路径和值名称。由于本例中的值名称本身就是一个路径,因此该方法认为它是键的一部分。有什么方法可以让这个方法识别它的值名称吗?
Here is the code that demonstrates the problem:
这是演示问题的代码:
var shell = WScript.CreateObject("WScript.Shell"); var keyPath = "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\SharedDlls\"; var valName = "C:\Program Files\Common Files\ACME Corp\AcmeUtil.dll"; WScript.Echo("count = " + shell.RegRead(keyPath + valName));
The error I am seeing is:
我看到的错误是:
WshShell.RegRead: Invalid root in registry key "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\SharedDlls\C:\Program Files\Common Files\ACME Corp\AcmeUtil.dll"
回答by Dror
The problem is in the slash...
You can read it with WMI instead as described here:
问题是在斜线......
你可以用WMI,而不是所描述的阅读这里:
Const HKEY_CURRENT_USER = &H80000001
Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\.\root\default:StdRegProv")
strKeyPath = "Software\ASoftware\ConfigList\MySettings"
strValueName = "xyz\abc"
oReg.GetStringValue HKEY_CURRENT_USER,strKeyPath,strValueName,strValue
wscript.echo strValue
Also: Scripts to manage Registry
另外:管理注册表的脚本