VBS: NIC Show Icon/Power Mgt Script
Here's script that I wrote (and probably borrowed some of it) to turn all nics' icons on, and disable power management for them. It only looks at nics with IP enabled.
You can also download it here.
(Just make sure you rename it to nicmod.vbs, or something similar)
'************************************************************************
'* VBS Script to:
'* Enable/Disable showing the icon in your system tray for connected NICs
'* Enable/Disable Power Management for Connected NICs
'*
'* 8 MAY 06 - Jase McCarty
'************************************************************************
'Let's setup our variables
Const HKLM = &H80000002 'HKEY_LOCAL_MACHINE info for registry writes
Dim objReg 'Registry Object
Dim objWMIService 'WMI Service Object
Dim arrayNetCards 'Array of all connected NICs
Dim objNetCard 'A specific NIC
Dim strNICguid '
Dim strShowNicKeyName 'Key Specific to the Network Adapters in CurrentControlSet
Dim strShowNicKeyName001 'Key Specific to the Network Adapters in ControlSet001
Dim strPnPCapabilitesKeyName 'Key Specific to the Network Adapters in CurrentControlSet
Dim strPnPCapabilitesKeyName001 'Key Specific to the Network Adapters in ControlSet001
Dim strComputer 'Name of computer to modify
You will have to reboot the system for the settings to take effect, or you could put it in a group policy to automatically run when a system performs a shutdown.
strComputer = "." 'Period = local computer
strShowNicKeyName = "SYSTEM\CurrentControlSet\Control\Network\{4D36E972-E325-11CE-BFC1-08002BE10318}\"
strShowNicKeyName001 = "SYSTEM\ControlSet001\Control\Network\{4D36E972-E325-11CE-BFC1-08002BE10318}\"
strPnPCapabilitiesKeyName = "SYSTEM\CurrentControlSet\Control\Class\{4D36E972-E325-11CE-BFC1-08002bE10318}\"
strPnPCapabilitiesKeyName001 = "SYSTEM\ControlSet001\Control\Class\{4D36E972-E325-11CE-BFC1-08002bE10318}\"
ShowNicdwValue = 1
'1 for ON, 0 for OFF
PnPdwValue = 56
'56 to disable "Allow the computer to turn off this device to save power."
'48 to enable "Allow the computer to turn off this device to save power."
'32 to enable "Allow the computer to turn off this device to save power."
' and enable "Allow this device to bring the computer out of standby."
'288 to enable "Allow the computer to turn off this device to save power."
' and enable "Allow this device to bring the computer out of standby."
' and enable "Only allow management stations to bring the computer out of standby."
On Error Resume Next
Set objReg = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\default:StdRegProv")
Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
'Look for the NICs that have IP enabled
Set arrayNetCards = objWMIService.ExecQuery ("Select * From Win32_NetworkAdapterConfiguration Where IPEnabled = True")
'Make changes on the NICs that have IP enabled
For Each objNetCard in arrayNetCards
strNICguid = objNetCard.SettingID 'Get the GUID of the NIC
strDeviceID = Mid(objNetCard.Caption,6,4) 'Get the DeviceID of the NIC
'Change the "Show icon in notification area when connected value"
objReg.SetDWORDValue HKLM, strShowNicKeyName & strNICguid & "\Connection", "ShowIcon", ShowNicdwValue
objReg.SetDWORDValue HKLM, strShowNicKeyName001 & strNICguid & "\Connection", "ShowIcon", ShowNicdwValue
'Change the Power Management Values
objReg.SetDWORDValue HKLM, strPnPCapabilitiesKeyName & strDeviceID & "\","PnPCapabilities",PnPdwValue
objReg.SetDWORDValue HKLM, strPnPCapabilitiesKeyName001 & strDeviceID & "\","PnPCapabilities",PnPdwValue
Next
Set objReg = Nothing
Set objWMIService = Nothing
'*** END OF SCRIPT ***
You could also modify this script to take a list of computers, and make the changes on all of them.
Enjoy.
Labels: VBS

5 Comments:
Isnt there a way to create a script for all network card, without having to view or check the device ID?
Isn't there a global policy for this problem?
This script will show the icon in the lower right for all nics that have TCP/IP bound to them.
Also, it will handle the power management of these devices.
I'm not 100%, but I do believe that there is a group policy that will address the power management piece.
I an pretty sure, there isn't a GPO that will have the nic icon turned on.
Your script doesn't seem to change the value of "Allow the computer to turn off this device to save power" option. It does seem to enable the other two when I set the value to 288, but the other still stays unchecked.
Have you had this happen any?
should
SYSTEM\CurrentControlSet001\
be
SYSTEM\ControlSet001\
?
Yeah, I need to correct that.
Thanks for the heads up.
Post a Comment
Links to this post:
Create a Link