Results 1 to 6 of 6

Thread: Wake On Lan

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Mar 2007
    Posts
    163

    Wake On Lan

    Hi all,

    Is there a way to detect programmatically if WOL is supported/enabled on a machine?

    Cheers,

    --Stav.

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Wake On Lan

    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.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3
    Master Of Orion ForumAccount's Avatar
    Join Date
    Jan 2009
    Location
    Canada
    Posts
    2,802

    Re: Wake On Lan

    vb.net Code:
    1. '//need a reference to System.Management
    2. Imports System.Management
    3.  
    4. Public Class Form1
    5.  
    6.     Protected Overrides Sub OnLoad(ByVal e As System.EventArgs)
    7.         MyBase.OnLoad(e)
    8.  
    9.         MessageBox.Show(WakeUpType.GetWakeUpType().ToString())
    10.  
    11.     End Sub
    12.  
    13. End Class
    14.  
    15. Public Class WakeUpType
    16.  
    17.     '//constants
    18.     Protected Const WMIQuery As String = "SELECT WakeUpType FROM Win32_ComputerSystem"
    19.     Protected Const WMIElement As String = "WakeUpType"
    20.  
    21.     '//constructors
    22.     Private Sub New()
    23.     End Sub
    24.  
    25.     '//methods
    26.     Public Shared Function GetWakeUpType() As WakeUpTypes
    27.         Try
    28.             Using searcher = New ManagementObjectSearcher(WakeUpType.WMIQuery)
    29.                 Using results = searcher.Get()
    30.                     For Each result In results
    31.                         Dim item = result.Item(WakeUpType.WMIElement)
    32.                         If item IsNot Nothing AndAlso _
    33.                            [Enum].IsDefined(GetType(WakeUpTypes), item) Then
    34.                             Return CType(item, WakeUpTypes)
    35.                         End If
    36.                     Next
    37.                 End Using
    38.             End Using
    39.         Catch ex As ManagementException
    40.         End Try
    41.         Return WakeUpTypes.Unknown
    42.     End Function
    43.  
    44.     '//enumerations
    45.     Public Enum WakeUpTypes As UShort
    46.         Reserved = &H0
    47.         Other = &H1
    48.         Unknown = &H2
    49.         APMTimer = &H3
    50.         ModemRing = &H4
    51.         LANRemote = &H5
    52.         PowerSwitch = &H6
    53.         PCIPME = &H7
    54.         ACPowerRestorted = &H8
    55.     End Enum
    56.  
    57. End Class

    Reference

  4. #4

    Thread Starter
    Addicted Member
    Join Date
    Mar 2007
    Posts
    163

    Re: Wake On Lan

    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:
    WakeUpType
    Data type: uint16
    Access type: Read-only

    Event that causes the system to power up.
    That made me think that it might be refering to the last wake up event...???
    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.

  5. #5
    Master Of Orion ForumAccount's Avatar
    Join Date
    Jan 2009
    Location
    Canada
    Posts
    2,802

    Re: Wake On Lan

    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?

  6. #6

    Thread Starter
    Addicted Member
    Join Date
    Mar 2007
    Posts
    163

    Re: Wake On Lan

    Both.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width