Enumerating Reg Key and Value

X

xpacifica

i need help i have a script that works beautifully. the only thing
that doesn't work is when i try to enumerate a registry key to retrieve
product information.

here's the path "SOFTWARE\Vendor\Product\Applications." at the end of
the path there is an array of subkey and each of they subkeys has
several string string values.

i have been successful in looping through the array and returning the
names of those subkeys however, i need to retrieve the value of a
string called "Installed" for each of the subkeys in the array. based
on the value of "Installed" i can tell whether or not a product is
successfully installed.

(ex. SOFTWARE\Vendor\Product\Applications\App1\Installed = 1)

i can do one or the other but not both. could someone please look at
my code and give me a boost?

Const HKEY_LOCAL_MACHINE = &H80000002

strComputer = "."
Set objWMIService = GetObject("winmgmts:" & "!\\" & strComputer &
"\root\cimv2")

Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" &
strComputer & "\root\default:StdRegProv")

strProductPath = "SOFTWARE\Vendor\Product\Applications"
oReg.EnumKey HKEY_LOCAL_MACHINE, strProductPath, arrSubKeys

For Each subkey In arrSubKeys
strSubKey = "Installed"
oReg.GetStringValue _
HKEY_LOCAL_MACHINE, strProductPath, arrSubKeys & subkey, _
strSubKey, strInstallValue

wscript.echo subkey ' <-- this works
wscript.echo strInstallValue ' <-- this does not work. it's
blank.
Next


thanks all!
 
J

Jonathan Liu [MSFT]

Here is the corrected code:

Const HKEY_LOCAL_MACHINE = &H80000002

strComputer = "."
Set objWMIService = GetObject("winmgmts:" & "!\\" & strComputer &
"\root\cimv2")

Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" &
strComputer & "\root\default:StdRegProv")

strProductPath = "SOFTWARE\Vendor\Product\Applications"
oReg.EnumKey HKEY_LOCAL_MACHINE, strProductPath, arrSubKeys

For Each subkey In arrSubKeys
strSubKey = "Installed"
oReg.GetStringValue HKEY_LOCAL_MACHINE, strProductPath & "\" & subkey,
strSubKey, strInstallValue '***<-----here is the fix

wscript.echo subkey ' <-- this works
wscript.echo strInstallValue ' <-- this does not work. it's
blank.
Next
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top