I just found this script for enabling Wake on LAN settings on a computer. I do not know anything about VBS and was wondering if someone could look over this script and let me know if it looks to be safe (not going to mess anything else up and such). I tested it on a test PC and it did what it was supposed to do but I am unsure if it did anything else that I would not want it to do. In addition, is there a way to turn off the user control pop-ups? I would like it to perform in silent/unattended mode. Right now, it asks the user to click OK a few times during the run process. Thanks in advance!





Option Explicit

Dim colNetworkAdapters
Dim objNetworkAdapter

Dim strDevInstanceName
Dim strNetworkAdapterID

'Query for all of the Win32_NetworkAdapters that are wired Ethernet (AdapterTypeId=0 corresponds to Ethernet 802.3)
Set colNetworkAdapters = GetObject("WinMgmts:{impersonationLevel=impersonate}//./root/Cimv2")_
.ExecQuery("SELECT * FROM Win32_NetworkAdapter WHERE AdapterTypeId=0")

WScript.Echo "Enabling WoL for the following adapters:"

For Each objNetworkAdapter In colNetworkAdapters
WScript.Echo " " & objNetworkAdapter.Name & " [" & objNetworkAdapter.MACAddress & "]"

strNetworkAdapterID = UCase(objNetworkAdapter.PNPDeviceID)

'Query for all of the MSPower_DeviceWakeEnable classes
Dim colPowerWakeEnables
Dim objPowerWakeEnable

Set colPowerWakeEnables = GetObject("WinMgmts:{impersonationLevel=impersonate}//./root/wmi")_
.ExecQuery("SELECT * FROM MSPower_DeviceWakeEnable")
'Compare the PNP Device ID from the network adapter against the MSPower_DeviceEnabled instances
For Each objPowerWakeEnable In colPowerWakeEnables
'We have to compare the leftmost part as MSPower_DeviceEnabled.InstanceName contains an instance suffix
strDevInstanceName = UCase(Left(objPowerWakeEnable.InstanceName, Len(strNetworkAdapterID)))
'Match found, enable WOL
If StrComp(strDevInstanceName, strNetworkAdapterID)=0 Then
objPowerWakeEnable.Enable = True
objPowerWakeEnable.Put_ 'Required to write the value back to the object
End If
Next
'Query for all of the MSNdis_DeviceWakeOnMagicPacketOnly classes
Dim colMagicPacketOnlys
Dim objMagicPacketOnly
Set colMagicPacketOnlys = GetObject("WinMgmts:{impersonationLevel=impersonate}//./root/wmi")_
.ExecQuery("SELECT * FROM MSNdis_DeviceWakeOnMagicPacketOnly")
'Compare the PNP Device ID from the network adapter against the MSNdis_DeviceWakeOnMagicPacketOnly instances
For Each objMagicPacketOnly In colMagicPacketOnlys
'We have to compare the leftmost part as MSNdis_DeviceWakeOnMagicPacketOnly.InstanceName contains an instance suffix
strDevInstanceName = UCase(Left(objMagicPacketOnly.InstanceName, Len(strNetworkAdapterID)))
'Match found, enable WOL for Magic Packets only
If StrComp(strDevInstanceName, strNetworkAdapterID)=0 Then
objMagicPacketOnly.EnableWakeOnMagicPacketOnly = True 'Set to false if you wish to wake on magic packets AND wake patterns
objMagicPacketOnly.Put_ 'Required to write the value back to the object
End If
Next
Next
0 Comments   [ + ] Show Comments

Comments

Please log in to comment

Rating comments in this legacy AppDeploy message board thread won't reorder them,
so that the conversation will remain readable.

Answers

0
The message popups in the above script is only to inform the users and these popups are because of "wscript.echo" commands in the script

supposed to do but I am unsure if it did anything else that I would not want it to do. In addition, is there a way to turn off the user control pop-ups? I would like it to perform in silent/unattended mode. Right now, it asks the user to click OK a few times during the run process. Thanks in advance!




Option Explicit

Dim colNetworkAdapters
Dim objNetworkAdapter

Dim strDevInstanceName
Dim strNetworkAdapterID

'Query for all of the Win32_NetworkAdapters that are wired Ethernet (AdapterTypeId=0 corresponds to Ethernet 802.3)
Set colNetworkAdapters = GetObject("WinMgmts:{impersonationLevel=impersonate}//./root/Cimv2")_
.ExecQuery("SELECT * FROM Win32_NetworkAdapter WHERE AdapterTypeId=0")

'WScript.Echo "Enabling WoL for the following adapters:"

For Each objNetworkAdapter In colNetworkAdapters
' WScript.Echo " " & objNetworkAdapter.Name & " [" & objNetworkAdapter.MACAddress & "]"

strNetworkAdapterID = UCase(objNetworkAdapter.PNPDeviceID)

'Query for all of the MSPower_DeviceWakeEnable classes
Dim colPowerWakeEnables
Dim objPowerWakeEnable

Set colPowerWakeEnables = GetObject("WinMgmts:{impersonationLevel=impersonate}//./root/wmi")_
.ExecQuery("SELECT * FROM MSPower_DeviceWakeEnable")
'Compare the PNP Device ID from the network adapter against the MSPower_DeviceEnabled instances
For Each objPowerWakeEnable In colPowerWakeEnables
'We have to compare the leftmost part as MSPower_DeviceEnabled.InstanceName contains an instance suffix
strDevInstanceName = UCase(Left(objPowerWakeEnable.InstanceName, Len(strNetworkAdapterID)))
'Match found, enable WOL
If StrComp(strDevInstanceName, strNetworkAdapterID)=0 Then
objPowerWakeEnable.Enable = True
objPowerWakeEnable.Put_ 'Required to write the value back to the object
End If
Next
'Query for all of the MSNdis_DeviceWakeOnMagicPacketOnly classes
Dim colMagicPacketOnlys
Dim objMagicPacketOnly
Set colMagicPacketOnlys = GetObject("WinMgmts:{impersonationLevel=impersonate}//./root/wmi")_
.ExecQuery("SELECT * FROM MSNdis_DeviceWakeOnMagicPacketOnly")
'Compare the PNP Device ID from the network adapter against the MSNdis_DeviceWakeOnMagicPacketOnly instances
For Each objMagicPacketOnly In colMagicPacketOnlys
'We have to compare the leftmost part as MSNdis_DeviceWakeOnMagicPacketOnly.InstanceName contains an instance suffix
strDevInstanceName = UCase(Left(objMagicPacketOnly.InstanceName, Len(strNetworkAdapterID)))
'Match found, enable WOL for Magic Packets only
If StrComp(strDevInstanceName, strNetworkAdapterID)=0 Then
objMagicPacketOnly.EnableWakeOnMagicPacketOnly = True 'Set to false if you wish to wake on magic packets AND wake patterns
objMagicPacketOnly.Put_ 'Required to write the value back to the object
End If
Next
Next
You can now try with this script........hope it works without any popups
Answered 02/04/2010 by: sunny07
Senior Yellow Belt

  • Hmm - it fails at the beginning of this line:
    For Each objMagicPacketOnly In colMagicPacketOnlys
    What am I doing wrong?
Please log in to comment
0
Thank you very much. That worked perfectly! I am planning to push this out domain wide and really did not want the pop-ups affecting the end user. It is bad enough teaching them how to use a computer let alone clicking OK on pop-ups. I would expect to get 100 calls asking what it was. Just this pass year, we just started enabling WOL when we build a new PC and such. Before that, we did not for whatever reason. Now we have the KBox, which does a lot but needs WOL enabled on the PCs in order for us to maintenance them during the night and such. I just did not want to spend two weeks going around to each PC enabling them by hand. Again, thank you for your help!!
Answered 02/04/2010 by: ustacp
Second Degree Blue Belt

Please log in to comment
Answer this question or Comment on this question for clarity