views:

1311

answers:

1

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:

[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.RegRead method 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?

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"
A: 

The problem is in the slash...
You can read it with WMI instead as described here.
Also: Scripts to manage Registry

Dror
Thank you very much! This helps me. Note that the WMI method will not work in javascript because javascript does not support passing values by reference. But that's fine-- I will simply switch to VB script.
Brian
It IS possible to read the registry with WMI in JScript, its just damn ugly, google "SpawnInstance_" and "ExecMethod_"
Anders