Script to enable NIC magic packets
An old script to share :-) It will enable magic packets for NIC devices.
'========================================================================== ' NAME: EnableNICMagicPackets ' 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/26/2011) - Modified the disable NIC power save to instead be ' enabled, so as to support Wake On LAN. Windows network devices ' should have selected (on Power Management) option ""Only allow a ' magic packet to wake the computer"" '========================================================================== 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\EnableNICMagicPackets.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/enable Power save on NIC. Value 256 (dec) converts to 100 (hex) in registry. oShell.RegWrite sNetworkAdapterReg & sIndexValue & ""\PnPCapabilities"", ""256"", ""REG_DWORD"" oVersionLog.WriteLine "" > Enabled network adapter power save on device """""" & oItem.Name & """""""" oVersionLog.WriteLine "" Set PnPCapabilities (dword) to 100 in "" & sNetworkAdapterReg & sIndexValue ' **************************************** ' Configure/enable WAN/LAN switching, possible when subkey LOM exists 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
November 22, 2014 at 7:01 pm
This entry is html-ized, quote marks and ampersands have been turned into HTML entities. Any chance of a fix?
November 23, 2014 at 11:29 am
Thanks for the heads up! I think I’ve fixed the code. Please let me know if there are any VBScript errors.