Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help searching the registry 1

Status
Not open for further replies.

Ednetman

Technical User
May 20, 2002
54
US
Hello, I am trying to write a script that will find the value "PnPCapabilities" under
"HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Class"

I have been able to find a script that finds what I am looking for, but I can't limit it to this specific path, it wants to search the entire registry. I have also found on MSDN how to limit the search area to the specific path above, but now i can't find specific values.

Can anyone help?

Thanks...
 
Try this. I don't have that value so I can't make an exact test. I have written a recursive function also to check all the reg keys from a given Key depth, if you need it. I noticed a lot of sub keys in mine. And maybe this is what your looking for.

Const HKEY_LOCAL_MACHINE = &H80000002
strComputer = "."

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

strKeyPath = "SYSTEM\CurrentControlSet\Control\Class"
strValueName = "PnPCapabilities"

oReg.GetDWORDValue _
HKEY_LOCAL_MACHINE ,strKeyPath,strValueName,dwValue

WScript.Echo "Current " & strVlueName & "value: " & dwValue


Also here is a listing of methods for the StdRegProv.
 
sorry i think i might be missing the point but..
Set WshShell = CreateObject("Wscript.Shell")
Msgbox WshShell.RegRead("HKLM\SYSTEM\CurrentControlSet\Control\Class\PnPCapabilities")
Set WshShell = Nothing
 
JBorecky,

Thanks for the script and the link. I actully used that page to create a script myself, but it didn't look quite the same as yours. However, the scripts (both mine and yours) do not return a value. The popup box says PnPCapabilites but there is nothing on the screen with it.

I should get 2 because of these keys:

[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Class\{4D36E972-E325-11CE-BFC1-08002BE10318}\0005]
"DriverDesc"="Intel(R) PRO/100 VM Network Connection"
"PnPCapabilities"=dword:00000020

and

[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Class\{4D36E972-E325-11CE-BFC1-08002bE10318}\0008]
"DriverDesc"="Broadcom NetXtreme Gigabit Ethernet"
"PnPCapabilities"=dword:00000038

----------------
mrmovie,
Thanks for trying, however since the value is nested deeper in the path, and the exact path is not known from machine to macine, the script you wrote doesn't quite work.
 
no worries, i wasnt clear what you were after...you need to use EnumKey

Set enumPrinters = WScript.CreateObject("Scripting.Dictionary")
Set refRegistry = GetObject("winmgmts:root\default:StdRegProv")
Const HKEY_CURRENT_USER = &H80000001
strRootKey = "Printers\Connections"

If refRegistry.EnumKey(HKEY_CURRENT_USER, strRootKey, arrSubKeys) = 0 Then
'init dictionary object of printers
For Each subKey In arrSubKeys
strPrinterMapping = ""
strPrinterMapping = Trim(LCase(CStr(subKey)))
If InStr(strPrinterMapping, ",,") = 1 Then
strPrinterMapping = Replace(strPrinterMapping, ",", "\")
If enumPrinters.Exists(strPrinterMapping) Then
'already have this one, unlikely
Else
'Wscript.Echo "adding " & strPrinterMapping & " to enumPrinters"
enumPrinters.Add strPrinterMapping, "1"
End If
End If
Next
End If
Set refRegistry = Nothing
 
Ok,

There are a few things in here that I would need to change.

What do I change this to?
Set enumPrinters = WScript.CreateObject("Scripting.Dictionary")

I belivie that I should change this:
Const HKEY_CURRENT_USER = &H80000001
strRootKey = "Printers\Connections"
to
const HKEY_LOCAL_MACHINE = &H80000002
strRootKey = "SYSTEM\CurrentControlSet\Control\Class"

after that, the logic in the script looks like it makes some changes instead of echoing a value.
 
This will get you started. [sleeping2]
What can I say I got bored. Hopefully you don't need a binary or Multistring value.


Const HKEY_LOCAL_MACHINE = &H80000002
strComputer = "."
const REG_SZ = 1
const REG_EXPAND_SZ = 2
const REG_BINARY = 3
const REG_DWORD = 4
const REG_MULTI_SZ = 7

strOriginalKeyPath = "SYSTEM\CurrentControlSet\Control\Class"

FindKeyValue(strOriginalKeyPath)

'-------------------------------------------------------------------------
Function FindKeyValue(strKeyPath)

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

errorCheck = oReg.EnumKey(HKEY_LOCAL_MACHINE, strKeyPath, arrSubKeys)

If (errorCheck=0 and IsArray(arrSubKeys)) then
For Each subkey In arrSubKeys
Wscript.Echo subkey
strNewKeyPath = strKeyPath & "\" & subkey
FindKeyValue(strNewKeyPath)
Next
End If

oReg.EnumValues HKEY_LOCAL_MACHINE, strKeyPath, _
arrValueNames, arrValueTypes

If (errorCheck=0 and IsArray(arrValueNames)) then
For i=0 To UBound(arrValueNames)
Wscript.Echo "Value Name: " & arrValueNames(i)
strValueName = arrValueNames(i)

Select Case arrValueTypes(i)
Case REG_SZ
oReg.GetStringValue HKEY_LOCAL_MACHINE,strKeyPath,strValueName,strValue
wscript.echo "Value: " & strvalue
Case REG_EXPAND_SZ
oReg.GetExpandedStringValue HKEY_LOCAL_MACHINE,strKeyPath,strValueName,strEXValue
wscript.echo "Value: " & strExvalue
Case REG_BINARY
oReg.GetBinaryValue HKEY_LOCAL_MACHINE,strKeyPath,strValueName,binaryValue
wscript.echo "Value: Binary"
Case REG_DWORD
oReg.GetDWORDValue HKEY_LOCAL_MACHINE,strKeyPath,strValueName,dwValue
wscript.echo "Value: " & dwvalue
Case REG_MULTI_SZ
oReg.GetMultiStringValue HKEY_LOCAL_MACHINE,strKeyPath,strValueName,MulstrValue
wscript.echo "Value: MultiString"
End Select

Next
End if
end Function
 
WOW! That produced more popup boxes than I knew what to do with. I was thinking something more along the lines of:

-------------------------------------------------------------
Option Explicit

Dim WSH
Dim strComputer
Dim objReg
Dim strKeyPath
Dim strValue

Const HKEY_LOCAL_MACHINE = &H80000002
Const DELETE = &H00010000

strComputer = "."

Set objReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & _
strComputer & "\root\default:StdRegProv")
strKeyPath = "SYSTEM\CurrentControlSet\Control\Class"
strEntryName = "PnPCapabilities"
objReg.GetStringValue HKEY_LOCAL_MACHINE, strKeyPath, strEntryName, strValue
If strValue = "00000038" Then
WScript.Echo ("Wake On LAN is Enabled") & " " & strKeyPath
WScript.Quit
Else
WScript.Echo ("Wake On LAN is ** NOT ** Enabled")
End If
-------------------------------------------------------------

I can't get it to work quite right yet, but the only value I wanted echoed is all instances of "PnPCapabilities."

Thanks for script though!
 
The value I am searching for is a DWORD, but I can't seem to make this script look for that type of value. Any ideas?
 
Replace your objReg.GetStringValue with oReg.GetDWORDValue
 
lol

I just got what you were talking about. I have a habit of running my scripts for a command prompt and use a cscript engine. Sorry about that. I bet it produced a few pop-ups.
 
JBorecky,

Thanks! Yes, I had to kill the script to see my machine again! There were many, many, popup boxes.

I made the change you suggested, however I still got the same error: Vaiableis undefined: 'strEntryName"

Then it came to me, I needed to add "Dim strEntryName" to the begining!

Now I am not getting any script errors, I just need to figure out how to get the response I want. I can't get it to tell me what the VALU is that it found, I get a message saying that "Object doesn't support this property or method: 'strValue'
 
:) Try this now. I promise it won't blow up your machine."

[red]
Const HKEY_LOCAL_MACHINE = &H80000002
strComputer = "."
const REG_SZ = 1
const REG_EXPAND_SZ = 2
const REG_BINARY = 3
const REG_DWORD = 4
const REG_MULTI_SZ = 7

strOriginalKeyPath = "SYSTEM\CurrentControlSet\Control\Class"

FindKeyValue(strOriginalKeyPath)

'-------------------------------------------------------------------------
Function FindKeyValue(strKeyPath)

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

errorCheck = oReg.EnumKey(HKEY_LOCAL_MACHINE, strKeyPath, arrSubKeys)

If (errorCheck=0 and IsArray(arrSubKeys)) then
For Each subkey In arrSubKeys
strNewKeyPath = strKeyPath & "\" & subkey
FindKeyValue(strNewKeyPath)
Next
End If

oReg.EnumValues HKEY_LOCAL_MACHINE, strKeyPath, _
arrValueNames, arrValueTypes

If (errorCheck=0 and IsArray(arrValueNames)) then
For i=0 To UBound(arrValueNames)
'Wscript.Echo "Value Name: " & arrValueNames(i)
if arrValueNames(i) = "PnPCapabilities" then
strValueName = arrValueNames(i)
oReg.GetDWORDValue HKEY_LOCAL_MACHINE, strKeyPath, strValueName, dwValue
wscript.echo "HKEY_LOCAL_MACHINE\" & strkeyPath & vbNewLine & "Contains: " & dwValue
end if
Next
End if
end Function
[/red]
 
Whoo - Hooo! This worked perfectly! I thank you very much for your efforts. It worked on my machine, let me try it on a few test machines.

What's up with that posting at 0:56? And I thought I pulled late hours!

~Ed
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top