Script to disable NIC power save features

Posted on Updated on

An old script to share :-)  It will parse the list of available network adapters to then disable power save features.

'==========================================================================
' NAME: SetNetworkPnPCapabilities
' AUTHOR: Nick Moseley , https://t3chn1ck.wordpress.com
' 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\SetNetworkPnPCapabilities.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 

' 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

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