Script integrated NIC power managment regedit

I want to push a regedit to disable the power management feature on the integrated Ethernet network adapter of numerous Windows 7 computers. I found the applicable KB, http://support.microsoft.com/kb/2740020, the problem however is that some of these computers will have multiple physical and virtual network adapters. Device 0000 or 0001 is not always the physical integrated NIC. On my computer for example, it is device 0007. Some computers are laptops and have both Ethernet and WiFi integrated NICs.

That being said, I need a script that can determine which device number is the physical Ethernet integrated NIC and then apply the regedit to the appropriate device in the registry. I've looked at various keys to see how one might isolate the exact device in the registry. It looks to me like "MediaType" and "PhysicalMediaType" combined would point to the right one. I've also noticed that for some device instances, either one or both of those keys are not even present. That would have to be taken into consideration when developing the script. Any help would be appreciated. Before anyone asks, sadly, using a GPO is not an option.
SnAkEhIpSAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

zalazarCommented:
A value of 14 for "*PhysicalMediaType" stands for Ethernet, 9 = Wireless.
In addition you might also check for the "*SpeedDuplex" value as network speed/duplex is only applicable for physical NICs.
The following script will display the physical NIC's registry device number.
Const HKEY_LOCAL_MACHINE = &H80000002
Dim WshShell, objReg

Set WshShell = WScript.CreateObject("WScript.Shell")
Set objReg = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\default:StdRegProv")

call GetPysicalNIC()

Wscript.Quit 0

'------------------------------------------------------------------------
' --------  SUBS  --------
'------------------------------------------------------------------------
Sub GetPysicalNIC()
  On Error Resume Next
  Dim strKeyName, aSubkeys, sSubkey, strKeyPath
  Dim sSpeedDuplexSetting, vPhysicalMediaType

  Wscript.echo "Reading NIC information"
  strKeyName = "SYSTEM\CurrentControlSet\Control\Class\{4D36E972-E325-11CE-BFC1-08002BE10318}"
  objReg.EnumKey HKEY_LOCAL_MACHINE, strKeyName, aSubkeys
  If IsArray(aSubkeys) = False Then Exit Sub

  For Each sSubkey In aSubkeys
    sSpeedDuplexSetting = ""
    vPhysicalMediaType = -1

    strKeyPath = strKeyName & "\" & sSubkey
    sComponentId = WshShell.RegRead("HKEY_LOCAL_MACHINE\" & strKeyPath & "\ComponentId")
    If LCase(Left(sComponentId, 4)) = "pci\" Then
      vPhysicalMediaType = WshShell.RegRead("HKEY_LOCAL_MACHINE\" & strKeyPath & "\*PhysicalMediaType")
      sSpeedDuplexSetting = WshShell.RegRead("HKEY_LOCAL_MACHINE\" & strKeyPath & "\*SpeedDuplex")
      If vPhysicalMediaType = 14 And sSpeedDuplexSetting <> "" Then
        Wscript.echo "Physical NIC;" & sSubkey & ";HKEY_LOCAL_MACHINE\" & strKeyPath
      End If
    End If
  Next
End Sub

Open in new window

0
zalazarCommented:
If you prefer "MediaType" and "PhysicalMediaType" then please see below:
Const HKEY_LOCAL_MACHINE = &H80000002
Dim WshShell, objReg

Set WshShell = WScript.CreateObject("WScript.Shell")
Set objReg = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\default:StdRegProv")

call GetPysicalNIC()

Wscript.Quit 0

'------------------------------------------------------------------------
' --------  SUBS  --------
'------------------------------------------------------------------------
Sub GetPysicalNIC()
  On Error Resume Next
  Dim strKeyName, aSubkeys, sSubkey, strKeyPath
  Dim vPhysicalMediaType, vMediaType

  Wscript.echo "Reading NIC information"
  strKeyName = "SYSTEM\CurrentControlSet\Control\Class\{4D36E972-E325-11CE-BFC1-08002BE10318}"
  objReg.EnumKey HKEY_LOCAL_MACHINE, strKeyName, aSubkeys
  If IsArray(aSubkeys) = False Then Exit Sub

  For Each sSubkey In aSubkeys
    vPhysicalMediaType = -1
    vMediaType = -1

    strKeyPath = strKeyName & "\" & sSubkey
    sComponentId = WshShell.RegRead("HKEY_LOCAL_MACHINE\" & strKeyPath & "\ComponentId")
    If LCase(Left(sComponentId, 4)) = "pci\" Then
      vPhysicalMediaType = WshShell.RegRead("HKEY_LOCAL_MACHINE\" & strKeyPath & "\*PhysicalMediaType")
      vMediaType = WshShell.RegRead("HKEY_LOCAL_MACHINE\" & strKeyPath & "\*MediaType")
      If vPhysicalMediaType = 14 And vMediaType = 0 Then
        Wscript.echo "Physical NIC;" & sSubkey & ";HKEY_LOCAL_MACHINE\" & strKeyPath
      End If
    End If
  Next
End Sub

Open in new window

0
SnAkEhIpSAuthor Commented:
I must be doing something wrong. "Const" is not recognized as an internal or external command, operable program or batch file...I get the same for each ensuing line. Once the device number is isolated, how do I apply the regedit to the appropriate key? It appears from the KB that the value becomes 0x118 (280) for the PnPCapabilities Key.
0
Hey MSSPs! What's your total cost of ownership?

WEBINAR: Managed security service providers often deploy & manage products from a variety of solution vendors. But is this really the best approach when it comes to saving time AND money? Join us on Aug. 15th to learn how you can improve your total cost of ownership today!

SnAkEhIpSAuthor Commented:
Disregard the error. I was not paying attention. But I still need to know how to pipe the result or otherwise merge the appropriate regedit based on the resulting device number.
0
zalazarCommented:
From what I read in the kb article http://support.microsoft.com/kb/2740020  the value should actually be 24 (Decimal).

quote/
A conflict happens for the DWORD value for the last step where Option 1 is only checked, if the following steps are done exactly as mentioned below:
•If you check all the boxes, then the value is 256 (0x100).
•If you un-check the box 1, which will grey out the other two, the value becomes 280 (0x118).
•If you check all the boxes except, the 3rd one, PNPCapabilites value becomes 0.
•If step 2 is repeated, the value becomes 24 (0x18).

Now, the values are different for the same setting because the way it has been achieved.
For deployment purpose, to keep the value for Allow the Computer to turn off this device to save power cleared, one needs to use the value 24 (0x18). Reason being, by default the option 1 and 2 are checked, which is same as DWORD value 0 of this key (even though the key does not exist in the registry by default). Hence, creating this key with a value 24 (0x18) in the deployment script/build process will inject this entry in the registry which in turn should uncheck the first box during server startup.

/quote

I have also checked the MicrosoftFixit55016.msi file which is in the KB article.
When unpacking the MSI and opening scriptfile "Binary.DisableAdapterPower".
The following line is present:
  Const strValueName = "PnPCapabilities"
  objReg.SetDWORDValue HKEY_LOCAL_MACHINE,targetKey & "\" & deviceNumber,strValueName,24

Below please find the script I created.
By modifying the variables you can adjust the settings if needed.
valPhysicalMediaType = 14
valMediaType = 0
valPnPCapabilities = 24
booSpeedDuplexCheck = "yes"

Const HKEY_LOCAL_MACHINE = &H80000002
Dim WshShell, objReg
Dim valPhysicalMediaType, valMediaType, valPnPCapabilities, booSpeedDuplexCheck

valPhysicalMediaType = 14    ' 14=Ethernet, 9=Wireless
valMediaType = 0
valPnPCapabilities = 24
booSpeedDuplexCheck = "yes"    ' Set to yes to check if *SpeedDuplex is set, set to no for no *SpeedDuplex check

Set WshShell = WScript.CreateObject("WScript.Shell")
Set objReg = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\default:StdRegProv")

call DisableNICPowerMgt()

Wscript.Quit 0

'------------------------------------------------------------------------
' --------  SUBS  --------
'------------------------------------------------------------------------
Sub DisableNICPowerMgt()
  On Error Resume Next
  Dim strKeyName, aSubkeys, sSubkey, strKeyPath
  Dim vPhysicalMediaType, vMediaType, vPnPCapabilities, sDriverDesc, sSpeedDuplex

  Wscript.echo "Reading NIC information"
  strKeyName = "SYSTEM\CurrentControlSet\Control\Class\{4D36E972-E325-11CE-BFC1-08002BE10318}"
  objReg.EnumKey HKEY_LOCAL_MACHINE, strKeyName, aSubkeys
  If IsArray(aSubkeys) = False Then Exit Sub

  For Each sSubkey In aSubkeys
    vPhysicalMediaType = -1
    vMediaType = -1
    vPnPCapabilities = -1
    sDriverDesc = ""
    sSpeedDuplex = ""

    strKeyPath = strKeyName & "\" & sSubkey
    sComponentId = WshShell.RegRead("HKEY_LOCAL_MACHINE\" & strKeyPath & "\ComponentId")
    If LCase(Left(sComponentId, 4)) = "pci\" Then
      vPhysicalMediaType = WshShell.RegRead("HKEY_LOCAL_MACHINE\" & strKeyPath & "\*PhysicalMediaType")
      vMediaType = WshShell.RegRead("HKEY_LOCAL_MACHINE\" & strKeyPath & "\*MediaType")
      vPnPCapabilities = WshShell.RegRead("HKEY_LOCAL_MACHINE\" & strKeyPath & "\PnPCapabilities")
      sDriverDesc = WshShell.RegRead("HKEY_LOCAL_MACHINE\" & strKeyPath & "\DriverDesc")
      If booSpeedDuplexCheck = "yes" Then
        sSpeedDuplex = WshShell.RegRead("HKEY_LOCAL_MACHINE\" & strKeyPath & "\*SpeedDuplex")
      Else
        sSpeedDuplex = "0"
      End If
      Err.Clear
      ' *PhysicalMediaType=14 (Ethernet), *MediaType=0, PnPCapabilities value is present, PnPCapabilities is not already 24, *SpeedDuplex should be present (if booSpeedDuplexCheck is set to yes)
      If vPhysicalMediaType = valPhysicalMediaType And vMediaType = valMediaType And vPnPCapabilities <> -1 And vPnPCapabilities <> 24 And sSpeedDuplex <> "" Then
        Wscript.echo "Configuring power management for physical NIC|" & sDriverDesc & "|" & sSubkey & "|HKEY_LOCAL_MACHINE\" & strKeyPath
        WshShell.RegWrite "HKEY_LOCAL_MACHINE\" & strKeyPath & "\PnPCapabilities", valPnPCapabilities, "REG_DWORD"
        If Err.Number = 0 Then
          Wscript.echo Now & "|SUCCESS|Configured power management|PnPCapabilities|" & valPnPCapabilities & "|" & CStr(Err.Number)
        Else
          Wscript.echo Now & "|ERROR|Configuring power management|PnPCapabilities|" & CStr(Err.Number)
        End If
      End If
    End If
    Err.Clear
  Next
End Sub

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
SnAkEhIpSAuthor Commented:
I see the value change as you described using the script you've provided. Let me verify what happens in my test environment. I'll reply again tomorrow.
0
SnAkEhIpSAuthor Commented:
When I run the script, the desired result is achieved, but not without a reboot of the target computer. That's perfectly fine and I really appreciate what you have done. Just out of curiosity though, do you think that the necessary reboot has something to do with the value that was selected or do you think that it is a necessity born of applying this particular registry edit?
0
SnAkEhIpSAuthor Commented:
Thank you for you zalazar!
0
zalazarCommented:
Good to know that it's working fine and thanks for the appreciation.
About your question. I assume that when it's changed via the GUI some additional procedures will be executed to "inform" the OS about the change.
When the value is only written into the registry the OS will not detect the change in setting and will only load the new setting at boot.
Thank you very much for the points and grade !
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Network Management

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.