I'm having trouble querying the registry for a key and value. I'm trying to find the active nic by querying on the control key in the enum\pci registry key. I have several nics and the active one has a control key in the registry so I'm trying to write a script to find the active nic. Unless someone knows of a better way to do this. Since the active nic will always be different in my environment i need a dynamic way of finding the active nic. Please help!
Const WMICONST = "winmgmts:{impersonationLevel=impersonate}!root\default:"
Dim strRoot, nPos, wshShell
Dim strFind, strPath, objRegistry, nRoot
strPath = "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Enum\PCI"
'strFind = "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Enum\PCI\VEN_10B7&DEV_9200&SUBSYS_00BE1028&REV_78\4&37725873&0&60F0\Control"
nPos = InStr(strPath, "\"
If nPos > 0 Then
strRoot = Mid(strPath, 1, InStr(strPath, "\"
- 1)
strPath = Mid(strPath, nPos + 1)
End If
Select Case strRoot
Case "HKEY_LOCAL_MACHINE", "HKLM"
nRoot = &H80000002
Case "HKEY_CURRENT_USER", "HKCU"
nRoot = &H80000001
Case "HKEY_CLASSES_ROOT"
nRoot = &H80000000
Case "HKEY_USERS"
nRoot = &H80000003
Case "HKEY_CURRENT_CONFIG"
nRoot = &H80000005
Case "HKEY_DYN_DATA"
nRoot = &H80000006
Case Else
WScript.Echo "Invalid registry root key: " & strRoot
WScript.Quit
End Select
Set objRegistry = GetObject(WMICONST & "StdRegProv"
RecurseReg strPath
Sub RecurseReg(strRegPath)
Dim nRet, aNames
Dim strValue, aValues, nF
nRet = objRegistry.EnumKey(nRoot, strRegPath, aNames)
If nRet = 0 Then
For nF = LBound(aNames) To UBound(aNames)
RecurseReg strRegPath & "\" & aNames(nF)
key = objRegistry.GetStringValue(nRoot, strRegPath, "Class", strvalue)
If strvalue = "Net" then
'wscript.echo strvalue
If objRegistry.EnumValues(nRoot, strRegPath, aValueNames, aValueTypes) = strRegPath & "\" & Control Then
wscript.echo "Key exists"
End If
End If
Next
End If
End Sub
Const WMICONST = "winmgmts:{impersonationLevel=impersonate}!root\default:"
Dim strRoot, nPos, wshShell
Dim strFind, strPath, objRegistry, nRoot
strPath = "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Enum\PCI"
'strFind = "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Enum\PCI\VEN_10B7&DEV_9200&SUBSYS_00BE1028&REV_78\4&37725873&0&60F0\Control"
nPos = InStr(strPath, "\"
If nPos > 0 Then
strRoot = Mid(strPath, 1, InStr(strPath, "\"
strPath = Mid(strPath, nPos + 1)
End If
Select Case strRoot
Case "HKEY_LOCAL_MACHINE", "HKLM"
nRoot = &H80000002
Case "HKEY_CURRENT_USER", "HKCU"
nRoot = &H80000001
Case "HKEY_CLASSES_ROOT"
nRoot = &H80000000
Case "HKEY_USERS"
nRoot = &H80000003
Case "HKEY_CURRENT_CONFIG"
nRoot = &H80000005
Case "HKEY_DYN_DATA"
nRoot = &H80000006
Case Else
WScript.Echo "Invalid registry root key: " & strRoot
WScript.Quit
End Select
Set objRegistry = GetObject(WMICONST & "StdRegProv"
RecurseReg strPath
Sub RecurseReg(strRegPath)
Dim nRet, aNames
Dim strValue, aValues, nF
nRet = objRegistry.EnumKey(nRoot, strRegPath, aNames)
If nRet = 0 Then
For nF = LBound(aNames) To UBound(aNames)
RecurseReg strRegPath & "\" & aNames(nF)
key = objRegistry.GetStringValue(nRoot, strRegPath, "Class", strvalue)
If strvalue = "Net" then
'wscript.echo strvalue
If objRegistry.EnumValues(nRoot, strRegPath, aValueNames, aValueTypes) = strRegPath & "\" & Control Then
wscript.echo "Key exists"
End If
End If
Next
End If
End Sub