Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/windows/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Windows 如何使用WshShell.regrad读取名称为文件路径的注册表值_Windows_Scripting_Registry_Wsh - Fatal编程技术网

Windows 如何使用WshShell.regrad读取名称为文件路径的注册表值

Windows 如何使用WshShell.regrad读取名称为文件路径的注册表值,windows,scripting,registry,wsh,Windows,Scripting,Registry,Wsh,我正在编写一些由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 Fil

我正在编写一些由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 [HKEY\U LOCAL\U MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\SharedDLS] “C:\\Program Files\\Common Files\\ACME Corp\\AcmeUtil.dll”=dword:00000002 “C:\\Program Files\\Common Files\\ACME Corp\\SuperEdit.ocx”=dword:0000000 1 我试图用这个方法来做这件事,但它似乎不起作用。我认为问题在于,该方法只接受一个参数,即要检索的值的串联键路径和值名称。由于本例中的值名本身就是路径,因此该方法认为它是键的一部分。有没有办法让这个方法识别它的值名

下面是演示问题的代码:

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)); var shell=WScript.CreateObject(“WScript.shell”); var keyPath=“HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\sharedlls\\”; var valName=“C:\\Program Files\\Common Files\\ACME Corp\\AcmeUtil.dll”; Echo(“count=“+shell.regrad(keyPath+valName)); 我看到的错误是:

WshShell.RegRead: Invalid root in registry key "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\SharedDlls\C:\Program Files\Common Files\ACME Corp\AcmeUtil.dll" WshShell.REGRAD:注册表项“HKEY\U LOCAL\U MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\SharedDLS\C:\Program Files\Common Files\ACME Corp\AcmeUtil.dll”中的根目录无效
问题在斜线中…
您可以改为使用WMI读取,如下所述:


另外:

非常感谢!这对我有帮助。请注意,WMI方法在javascript中不起作用,因为javascript不支持通过引用传递值。但这很好——我将简单地切换到VB脚本。在JScript中使用WMI读取注册表是可能的,它非常难看,google“SpawnInstance”和“ExecMethod”
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