none
Script to enable "Allow this device to bring the computer out of standby" RRS feed

  • Question

  • Hello everyone,

    I'm looking for a VBScript to enable the following settings on a Local Nic in Windows XP:

    "Allow this device to bring the computer out of standby"

    "Only allow management stations to bring the computer out of standby"

     

    I'd like to allow our fleet to go into Standby, but without those settings enabled we cannot initiate Wake on Lan during that state.  If I enable those settings on an image or driver, Sysprep wacks those settings.  I found a VBScript to enable "Allow the computer to turn off this device to save power" but not a script to enable the previous settings.

    Any ideas?  Thanks!

    Wednesday, April 21, 2010 3:22 PM

Answers

  • There is a command line tool named Powercfg.exe available in Windows XP you can use to set that option. The command looks like this:

    POWERCFG /DEVICEENABLEWAKE "Device name"

    You would first need to get the NIC name as seen in the Device Manager.


    Uros Calakovic
    • Marked as answer by IamMred Wednesday, April 28, 2010 2:49 AM
    Monday, April 26, 2010 7:28 AM
    Moderator
  • You could try this: Get the Nic name from the Win32_NetworkAdapter class and use it with Powercfg. Here is a sample:

    Const intWindowStyle = 0
    
    Set objWshShell = CreateObject("WScript.Shell")
    
    Set objWmi = GetObject("winmgmts:root\cimv2")
    Set colAdapterConfigs = objWmi.ExecQuery _
      ("Select * From Win32_NetworkAdapterconfiguration " _
      & " Where IPEnabled = True")
      
    For Each objAdapterConfig In colAdapterConfigs
      Set colAdapters = _
        objAdapterConfig.Associators_(, "Win32_NetworkAdapter")
      For Each objAdapter In colAdapters
        objWshShell.Run "%comspec% /c powercfg /deviceenablewake """ _
        & objAdapter.Name & """", intWindowStyle, True
      Next
    Next

     

    This is not ideal, but makes the script more flexible.

     


    Uros Calakovic
    • Proposed as answer by LikeToCodeModerator Tuesday, April 27, 2010 3:07 AM
    • Marked as answer by IamMred Wednesday, April 28, 2010 2:49 AM
    Monday, April 26, 2010 4:28 PM
    Moderator
  • I did some searching and found this blog post. It appears that it is possible to enable both options using WMI. "Allow this device to bring the computer out of standby" is represented by the MSPower_DeviceWakeEnable class and the "Only allow management stations to bring the computer out of standby" option by the MSNdis_DeviceWakeOnMagicPacketOnly class, both located in root\wmi namespace. At the bottom of the page there is a script that enables both options on all Ethernet network cards. Here is a script based on that one to enable the options on all network cards where 'IPEnabled = True':

    ' Connect to Root\Cimv2 and Root\Wmi namespaces
    
    Set objCimv2 = GetObject("winmgmts:root\cimv2")
    Set objWmi = GetObject("winmgmts:root\wmi")
    
    ' Get all network adapters where IPEnabled is true
    
    Set colAdapterConfigs = objCimv2.ExecQuery _
      ("Select * From Win32_NetworkAdapterconfiguration Where IPEnabled = True")
     
    For Each objAdapterConfig In colAdapterConfigs
      
      Set colAdapters = objAdapterConfig.Associators_(, "Win32_NetworkAdapter")
      
      For Each objAdapter In colAdapters  
       
        ' Get the matching instance MSPower_DeviceWakeEnable 
        
        Set colDeviceWakeEnable = objWmi.ExecQuery _
          ("Select * From MSPower_DeviceWakeEnable " _
          & "Where InstanceName Like '" _
          & Replace(objAdapter.PNPDeviceId, "\", "\\") & "%'")
       
        ' Enable "Allow this device to bring the computer out of standby"
        
        For Each objDeviceWakeEnable In colDeviceWakeEnable
          objDeviceWakeEnable.Enable = True
          objDeviceWakeEnable.Put_
          WScript.Echo "Enabled Wake-on-LAN on " & objAdapter.Name
        Next
        
        ' Get the matching MSNdis_DeviceWakeOnMagicPacketOnly instance
        
        Set colDeviceWakeOnMagicPacketOnly = objWmi.ExecQuery _
          ("Select * From MSNdis_DeviceWakeOnMagicPacketOnly " _
          & "Where InstanceName Like '" _
          & Replace(objAdapter.PNPDeviceId, "\", "\\") & "%'")  
        
        ' Enable "Only allow management stations to bring the computer out of standby"
          
        For Each objDeviceWakeOnMagicPacketOnly In colDeviceWakeOnMagicPacketOnly
          objDeviceWakeOnMagicPacketOnly.EnableWakeOnMagicPacketOnly = True
          objDeviceWakeOnMagicPacketOnly.Put_
        WScript.Echo "Enabled Magic Packet Only on " & objAdapter.Name
        Next
          
      Next
      
    Next
    

     

     


    Uros Calakovic
    • Marked as answer by IamMred Wednesday, April 28, 2010 2:49 AM
    Tuesday, April 27, 2010 7:41 PM
    Moderator

All replies

  • There is a command line tool named Powercfg.exe available in Windows XP you can use to set that option. The command looks like this:

    POWERCFG /DEVICEENABLEWAKE "Device name"

    You would first need to get the NIC name as seen in the Device Manager.


    Uros Calakovic
    • Marked as answer by IamMred Wednesday, April 28, 2010 2:49 AM
    Monday, April 26, 2010 7:28 AM
    Moderator
  • Hello,

    I did find that command but I was hoping that there was another universal method of doing it.  We have quite a few models of machines and I was hoping not to have to create a custom script/command for each one.

    Monday, April 26, 2010 2:20 PM
  • You could try this: Get the Nic name from the Win32_NetworkAdapter class and use it with Powercfg. Here is a sample:

    Const intWindowStyle = 0
    
    Set objWshShell = CreateObject("WScript.Shell")
    
    Set objWmi = GetObject("winmgmts:root\cimv2")
    Set colAdapterConfigs = objWmi.ExecQuery _
      ("Select * From Win32_NetworkAdapterconfiguration " _
      & " Where IPEnabled = True")
      
    For Each objAdapterConfig In colAdapterConfigs
      Set colAdapters = _
        objAdapterConfig.Associators_(, "Win32_NetworkAdapter")
      For Each objAdapter In colAdapters
        objWshShell.Run "%comspec% /c powercfg /deviceenablewake """ _
        & objAdapter.Name & """", intWindowStyle, True
      Next
    Next

     

    This is not ideal, but makes the script more flexible.

     


    Uros Calakovic
    • Proposed as answer by LikeToCodeModerator Tuesday, April 27, 2010 3:07 AM
    • Marked as answer by IamMred Wednesday, April 28, 2010 2:49 AM
    Monday, April 26, 2010 4:28 PM
    Moderator
  • Looks like that works!  I'll test it some more but it looks like the ticket!  Thanks!
    Monday, April 26, 2010 9:40 PM
  • Is it possible to also enable the associated "Only allow management stations to bring the computer out of standby" ?  Thanks!
    Tuesday, April 27, 2010 5:16 PM
  • I did some searching and found this blog post. It appears that it is possible to enable both options using WMI. "Allow this device to bring the computer out of standby" is represented by the MSPower_DeviceWakeEnable class and the "Only allow management stations to bring the computer out of standby" option by the MSNdis_DeviceWakeOnMagicPacketOnly class, both located in root\wmi namespace. At the bottom of the page there is a script that enables both options on all Ethernet network cards. Here is a script based on that one to enable the options on all network cards where 'IPEnabled = True':

    ' Connect to Root\Cimv2 and Root\Wmi namespaces
    
    Set objCimv2 = GetObject("winmgmts:root\cimv2")
    Set objWmi = GetObject("winmgmts:root\wmi")
    
    ' Get all network adapters where IPEnabled is true
    
    Set colAdapterConfigs = objCimv2.ExecQuery _
      ("Select * From Win32_NetworkAdapterconfiguration Where IPEnabled = True")
     
    For Each objAdapterConfig In colAdapterConfigs
      
      Set colAdapters = objAdapterConfig.Associators_(, "Win32_NetworkAdapter")
      
      For Each objAdapter In colAdapters  
       
        ' Get the matching instance MSPower_DeviceWakeEnable 
        
        Set colDeviceWakeEnable = objWmi.ExecQuery _
          ("Select * From MSPower_DeviceWakeEnable " _
          & "Where InstanceName Like '" _
          & Replace(objAdapter.PNPDeviceId, "\", "\\") & "%'")
       
        ' Enable "Allow this device to bring the computer out of standby"
        
        For Each objDeviceWakeEnable In colDeviceWakeEnable
          objDeviceWakeEnable.Enable = True
          objDeviceWakeEnable.Put_
          WScript.Echo "Enabled Wake-on-LAN on " & objAdapter.Name
        Next
        
        ' Get the matching MSNdis_DeviceWakeOnMagicPacketOnly instance
        
        Set colDeviceWakeOnMagicPacketOnly = objWmi.ExecQuery _
          ("Select * From MSNdis_DeviceWakeOnMagicPacketOnly " _
          & "Where InstanceName Like '" _
          & Replace(objAdapter.PNPDeviceId, "\", "\\") & "%'")  
        
        ' Enable "Only allow management stations to bring the computer out of standby"
          
        For Each objDeviceWakeOnMagicPacketOnly In colDeviceWakeOnMagicPacketOnly
          objDeviceWakeOnMagicPacketOnly.EnableWakeOnMagicPacketOnly = True
          objDeviceWakeOnMagicPacketOnly.Put_
        WScript.Echo "Enabled Magic Packet Only on " & objAdapter.Name
        Next
          
      Next
      
    Next
    

     

     


    Uros Calakovic
    • Marked as answer by IamMred Wednesday, April 28, 2010 2:49 AM
    Tuesday, April 27, 2010 7:41 PM
    Moderator