November 22, 2024
VBS

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 = “SYSTEMCurrentControlSetControlNetwork{4D36E972-E325-11CE-BFC1-08002BE10318}”
strShowNicKeyName001 = “SYSTEMControlSet001ControlNetwork{4D36E972-E325-11CE-BFC1-08002BE10318}”
strPnPCapabilitiesKeyName = “SYSTEMCurrentControlSetControlClass{4D36E972-E325-11CE-BFC1-08002bE10318}”
strPnPCapabilitiesKeyName001 = “SYSTEMControlSet001ControlClass{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 & “rootdefault:StdRegProv”)
Set objWMIService = GetObject(“winmgmts:{impersonationLevel=impersonate}!\” & strComputer & “rootcimv2”)

‘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.

18 thoughts on “VBS: NIC Show Icon/Power Mgt Script

  1. 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?

  2. 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.

  3. 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?

  4. Haven’t tried it…

    But keep in mind, Vista handles the display differently…

    I’ll have to run it against my Vista box, and see if it works.

    I’ll report back.

  5. I’ve been using this script for the past few years on XP systems and have not had any issues. We’re currently preparing to roll out Windows 7 and I was hoping that someone could tell me if this will work on Windows 7 or if it needs to be modified to work correctly. The piece I am mainly concerned about is disabling the “Allow the computer to turn off this device to save power” so that I don’t have to do this manually for every system.

    Thanks

    1. Hi Renae,

      For Windows 7, the PnPdwValue needs to be 280 (decimal) rather than 56 (decimal). The issue is, with Windows 7, this registry change does not get pushed to the nic. You may want to run the script, and then execute a reboot. I would imagine that the setting would be persistent. Unfortunately I don’t have a Windows 7 system available to test this on. With that, your mileage may vary.

      I hope that helps,
      Jase

  6. @Jase

    Hi Jase –

    I made the change within the script from PnPdwValue = 56 to PnPdwValue = 280 and rebooted, but the setting didn’t change.

    If you have any other suggestions I’d very much appreciate it.

    Thanks so much.
    Renae

  7. @Jase

    Hi Jase –

    I went to the link you provided and downloaded the powershell script. It doesn’t work, and since I’m not familiar with Powershell I’m not sure how to resolve the error that I’m getting. In trying to troubleshoot the script itself, I broke it down into sections and instead of using the variables $computer and $namespace I supplied the information I wanted to pass directly. I also had to make a couple of edits to the commands to get them to execute. I’m running the Powershell ISE to debug the script and have used “run as administrator” to be sure that it wasn’t due to permissions. The firewall is also turned off.

    This is what I’m getting when I run the script:

    NIC Power Management settings

    Enable “Allow the computer to turn off this device to save power”
    Get-WmiObject : The RPC server is unavailable. (Exception from HRESULT: 0x800706BA)
    At E:set-WOL-Power-Management.ps1:36 char:14
    + Get-WmiObject <<<< -computername %COMPUTERNAME% Win32_NetworkAdapter -filter "AdapterTypeId='Ethernet 802.3'" | % {
    + CategoryInfo : InvalidOperation: (:) [Get-WmiObject], COMException
    + FullyQualifiedErrorId : GetWMICOMException,Microsoft.PowerShell.Commands.GetWmiObjectCommand

    Enable "Allow this device to wake the computer"
    Get-WmiObject : The RPC server is unavailable. (Exception from HRESULT: 0x800706BA)
    At E:set-WOL-Power-Management.ps1:48 char:14
    + Get-WmiObject <<<< -computername %COMPUTERNAME% Win32_NetworkAdapter -filter "AdapterTypeId='Ethernet 802.3'" | % {
    + CategoryInfo : InvalidOperation: (:) [Get-WmiObject], COMException
    + FullyQualifiedErrorId : GetWMICOMException,Microsoft.PowerShell.Commands.GetWmiObjectCommand

    Enable "Wake on Magic Packet"
    Get-WmiObject : The RPC server is unavailable. (Exception from HRESULT: 0x800706BA)
    At E:set-WOL-Power-Management.ps1:59 char:14
    + Get-WmiObject <<<< -computername %COMPUTERNAME% Win32_NetworkAdapter -filter "AdapterTypeId='Ethernet 802.3'" | % {
    + CategoryInfo : InvalidOperation: (:) [Get-WmiObject], COMException
    + FullyQualifiedErrorId : GetWMICOMException,Microsoft.PowerShell.Commands.GetWmiObjectCommand

    Thanks,
    Renae

  8. I have been using this VB script for a couple of years to set XP NICS, but it failed when applied to Win7 machines. After screwing around with Powershell (you think that this would be easy) I finally went back to the VB script. By monitoring the registry setting I determined that the DWORD value of 0 allows the NIC to go to sleep and wake up on the network (in our case RDP). 16 clears all the checks and 100 (256) checks them all (I didn’t narrow that one down as it is useless to me.) After rebooting Broadcom and Realtek NICs have the correct settings. RDP times out before the computer is fully awake, but launching a second time connects. I also learned the Windows 7 does not wake up to ICMP ping, so I will have to retrain my users. Thought you might like to know. I appreciate you sharing your work.

  9. I have been using this VB script for a couple of years to set XP NICS, but it failed when applied to Win7 machines. After screwing around with Powershell script (you think that this would be easy) but it looks like you need to input credentials and computer name. I finally went back to the VB script. By monitoring the registry setting I determined that the DWORD value of 0 allows the NIC to go to sleep and wake up on the network (in our case RDP). 16 clears all the checks and 100 (256) checks them all (I didn’t narrow that one down as it is useless to me.) After rebooting Broadcom and Realtek NICs have the correct settings. RDP times out before the computer is fully awake, but launching a second time connects. I also learned the Windows 7 does not wake up to ICMP ping, so I will have to retrain my users. Thought you might like to know. I appreciate you sharing your work.

  10. Jase/Renae –

    Just FWIW I tried the PS script and got the same RPC server unavailable errors that you did. After some troubleshooting, I found that every time that error popped up (well, actually every 3x) it was due to a device being offline. I may not be able to figure out the WMI part and I barely know PS, but I was able to tweak the script just enough for it to show me the system name before it tried to update it and added a loop to it so it’d apply to all computers in the domain. Mucho thanks for the info!

  11. For those who don’t know, you can’t just ‘execute/run’ a powershell script from command line, without some added bells & whistles:
    1) Take the code from the powershell link, save it as “soemthing.ps1”
    2) Either go into powershell or do “powershell something.ps1”
    You may need to enable scripting (remove scripting restrictions) for it to run.

    J.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.