VBScript Disable NIC Power Management Setting

Posted on Updated on

The following VBScript will disable NIC power save features.

'==========================================================================
' NAME: SetNetworkPnPCapabilities
' AUTHOR: Nick Moseley , <a href="https://t3chn1ck.wordpress.com">https://t3chn1ck.wordpress.com</a>
' COMMENT: Parses list of available network adapters to then disable power
' save features.  For more info, see Microsoft KB837058
' VERSION HISTORY:
' 1.0 (05/09/2011) - Initial script
' 1.1 (05/10/2011) - Fixed logical bug within the If statement for Wan/Lan
' 2.0 (05/10/2011) - Added logging into registry for future inventory
' 3.0 (08/17/2011) - Commented out changes to disable NIC power save as
'  this needs to be enabled in order to support WOL
'==========================================================================
Option Explicit
Const ForAppending = 8

Dim oShell, oWMI, colNetworkAdapterItems, sNetworkAdapterReg
Set oShell = CreateObject ("WScript.Shell")
Set oWMI = GetObject("winmgmts:\\.\root\cimv2")
Set colNetworkAdapterItems = oWMI.ExecQuery ("Select * from Win32_NetworkAdapter")
sNetworkAdapterReg = "HKLM\SYSTEM\CurrentControlSet\Control\Class\{4D36E972-E325-11CE-BFC1-08002bE10318}\"

' Logging
Dim oFSO, oVersionLog
Set oFSO = CreateObject ("Scripting.FileSystemObject")
Set oVersionLog = oFSO.OpenTextFile ("C:\Windows\Temp\NicPower.log", ForAppending, True)
oVersionLog.WriteLine "Configuration of Network Adapters"
oVersionLog.WriteLine "  => Started (" & Date & " " & Time & ")"

' Get all objects and take action on network adapters
Dim oItem, sIndexValue, sLomValue
For Each oItem In colNetworkAdapterItems
If InStr(lcase(oItem.Name),"wan miniport")=0 _
And InStr(LCase(oItem.Name),"microsoft isatap")=0 _
And Trim(oItem.Name)<>"RAS Async Adapter" _
And InStr(LCase(oItem.Name),"cisco")=0 Then
If oItem.Index < 10 Then
sIndexValue = "000" & oItem.Index
Else
sIndexValue = "00" & oItem.Index
End If

' ****************************************
' IMPORTANT: NIC power save as needs to be enabled in order to support WOL
' Configure/disable Power save on NIC
oShell.RegWrite sNetworkAdapterReg & sIndexValue & "\PnPCapabilities", "56", "REG_DWORD"
oVersionLog.WriteLine "  => Disabled network adapter power save on device """ & oItem.Name & """"
oVersionLog.WriteLine "     Set PnPCapabilities (dword) to 38 in " & sNetworkAdapterReg & sIndexValue
' ****************************************

' Configure/enable WAN/LAN switching
sLomValue = ReadRegistryKey (sNetworkAdapterReg & sIndexValue, "LOM")
If sLomValue<>"1"  And sLomValue<>"null" Then
oShell.RegWrite sNetworkAdapterReg & sIndexValue & "\LOM", "1", "REG_SZ"
oVersionLog.WriteLine "  => Enabled WAN/LAN switching on device """ & oItem.Name & """"
oVersionLog.WriteLine "     Set LOM (string) to ""1"" in " & sNetworkAdapterReg & sIndexValue
End If
End If
Next
' Set registry values for SCCM inventory
oShell.RegWrite "HKLM\Software\CompanyName\Image Info\DisabledNICPowerSave", "True", "REG_SZ"

' End
oVersionLog.WriteLine "  => Completed (" & Date & " " & Time & ")"
WScript.Quit (oVersionLog.Close)

Function ReadRegistryKey (sReadKey, sReadValue)
On Error Resume Next
Dim sGetValue
sGetValue = oShell.RegRead (sReadKey & "\" & sReadValue)

If Err.Number <> 0 Then
ReadRegistryKey = "null"
Else
ReadRegistryKey = cstr(sGetValue)
End If
End Function
Advertisements

2 thoughts on “VBScript Disable NIC Power Management Setting

    Patrick Rowley said:
    July 3, 2013 at 3:55 pm

    Nick, trying to get this script to work; I’m not a vbscript guy…

    I just need the script to turn off power management for any NIC (WOL is not a concern at this point.) Your comments seem to state that something needs to be commented out for this to work? As of right now, the script does not disable Windows’ ability to turn off the NIC to save power…

    TIA,
    -Patrick

      N. Moseley responded:
      July 7, 2013 at 10:03 am

      The comments were just for personal change tracking for how I had previously modified the script – so that comment can be ignored. When you ran the script, did you execute it from an elevated command prompt? Did you check the formatting of the script from your copy/paste of the code? Also, can you tell me what line generated the error?

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s