Hi all,
Is there a way to detect programmatically if WOL is supported/enabled on a machine?
Cheers,
--Stav.
Printable View
Hi all,
Is there a way to detect programmatically if WOL is supported/enabled on a machine?
Cheers,
--Stav.
I'm sure that it is and that it would be done using WMI. I have no idea what the details would be, but that gives you an avenue to investigate.
vb.net Code:
'//need a reference to System.Management Imports System.Management Public Class Form1 Protected Overrides Sub OnLoad(ByVal e As System.EventArgs) MyBase.OnLoad(e) MessageBox.Show(WakeUpType.GetWakeUpType().ToString()) End Sub End Class Public Class WakeUpType '//constants Protected Const WMIQuery As String = "SELECT WakeUpType FROM Win32_ComputerSystem" Protected Const WMIElement As String = "WakeUpType" '//constructors Private Sub New() End Sub '//methods Public Shared Function GetWakeUpType() As WakeUpTypes Try Using searcher = New ManagementObjectSearcher(WakeUpType.WMIQuery) Using results = searcher.Get() For Each result In results Dim item = result.Item(WakeUpType.WMIElement) If item IsNot Nothing AndAlso _ [Enum].IsDefined(GetType(WakeUpTypes), item) Then Return CType(item, WakeUpTypes) End If Next End Using End Using Catch ex As ManagementException End Try Return WakeUpTypes.Unknown End Function '//enumerations Public Enum WakeUpTypes As UShort Reserved = &H0 Other = &H1 Unknown = &H2 APMTimer = &H3 ModemRing = &H4 LANRemote = &H5 PowerSwitch = &H6 PCIPME = &H7 ACPowerRestorted = &H8 End Enum End Class
Reference
Thanks for the replies guys.
ForumAccount, I have tried the code and it returns "PowerSwitch". There is only 1 "result" in "results" by the way.
The msdn reference page confused me a bit too. It says the following:
That made me think that it might be refering to the last wake up event...???Quote:
WakeUpType
Data type: uint16
Access type: Read-only
Event that causes the system to power up.
Just to eliminate any doubts that were created I have tried running the code after waking up the machine using WOL and the result of the code was once again "PowerSwitch"...
Any more input will be much appreciated.
Cheers,
--Stav.
I'm not really sure at this point. When you say 'enabled on a machine' do you mean enabled in the bios? Or enabled in the network adapter?
Both.