Results 1 to 22 of 22

Thread: Automatically Wake Up The Computer From Hibernation [VB6] [Win2000 or later]

  1. #1

    Thread Starter
    PoorPoster iPrank's Avatar
    Join Date
    Oct 2005
    Location
    In a black hole
    Posts
    2,728

    Talking Automatically Wake Up The Computer From Hibernation [VB6] [Win2000 or later]

    The Story:

    I was looking for a alarm clock software that will wake me up at 6:00am so that I can start spaming here at VBF as soon as possible. But I don't want to keep my PC turned on all night.
    Many modern motherboards supports automatic boot-up alarm. But my motherboard doesn't. 'Wake on LAN' may be an option, but I don't have a LAN. 'Wake on Modem Ring' may be another option, but I gave my dial-up modem to my friend.
    So, here is my workaround: Keep the PC in Hibernate (Suspend) mode and wake it up at 6:00am.

    The Program:

    This program simply puts the PC in hibernation state and wakes it up at a pre-defined time. Optionally it can sound an alarm when it wakes up. (You must keep the power on. )

    Before We Begin:

    1.) This works only in Win2000 or later
    2.) Make sure your motherboard supports ACPI S4 state.
    2.) Make sure hibernation is enabled in Windows. Go to, ControlPanel>PowerOptions and in the 'Hibernation' tab, check the 'Enable hibernation' checkbox.

    Enter the Coder:

    Open the project in VB and run it. Press the 'Test' button.
    If everything is ok, your system will go to Hibernation. Don't turn off power. Your system will wake up automatically after 2 minutes.
    If your system doesn't wake up within 3-4 minutes, press the power button of your computer.

    Note: Hibernation is very much OS/Motherboard/DeviceDriver dependent. Make sure Windows can hibernate your computer perfectly. Save all work before testing.

    How it works ?

    Basically I have done nothing but merging the following codes:
    How To Use SetWaitableTimer With Visual Basic
    SetSystemPowerState

    SetSystemPowerState initiates a hibernation and just then, CreateWaitableTimer and SetWaitableTimer creates and sets a waitable timer with passing True to the fResume parameter. When the timer event fires, Windows automatically wakes-up.
    Quote Originally Posted by MSDN
    fResume
    [in] Specifies whether to restore a system in suspended power conservation mode when the timer state is set to signaled. If fResume is TRUE on a platform that does not support a restore, the call will succeed, but GetLastError returns ERROR_NOT_SUPPORTED
    In addition, I have subclassed the form. When Windows or any other program tries to suspend the system, I'm discarding the operation and initiating my own Hibernate&WakeUp routine. (Will be useful if we keep it running in background or in systray. In v2.0 may be. )

    End Sub:
    I have tested this code on Windows 2003 Server and it is working ok.
    Special thanks to fahad k for testing this code.

    This is my first codebank submission. Please feel free to comment or slap me.
    Attached Files Attached Files
    Last edited by Hack; Mar 30th, 2006 at 12:39 PM.
    Usefull VBF Threads/Posts I Found . My flickr page .
    "I love being married. It's so great to find that one special person you want to annoy for the rest of your life." - Rita Rudner


  2. #2
    Frenzied Member I_Love_My_Vans's Avatar
    Join Date
    Jan 2005
    Location
    In the PHP compiler
    Posts
    1,275

    Re: Automatically Wake Up The Computer From Hibernation [VB6] [Win2000 or later]

    Hell yea!!! well im guessing that, but i have been looking for smmurt like this. well played

    ILMV

  3. #3

    Thread Starter
    PoorPoster iPrank's Avatar
    Join Date
    Oct 2005
    Location
    In a black hole
    Posts
    2,728

    Re: Automatically Wake Up The Computer From Hibernation [VB6] [Win2000 or later]

    Thanks dude.

    I have tested this in my friends' PC, WinXP-SP2, and it works there too.
    Usefull VBF Threads/Posts I Found . My flickr page .
    "I love being married. It's so great to find that one special person you want to annoy for the rest of your life." - Rita Rudner


  4. #4
    Addicted Member zahadumy's Avatar
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    187

    Re: Automatically Wake Up The Computer From Hibernation [VB6] [Win2000 or later]

    VB 6? Can you convert it to .NET?
    The first step in solving a problem is to define the problem clearly.

    -----
    Icons | EZIconConverter | Popup Messages
    101 samples: 2003 2005
    Code converter: C# -> VB .NET | VB .NET -> C# | VB .NET <-> C#


    -----
    Visual Studio 2005/.NET Framework 2.0

  5. #5
    Frenzied Member thegreatone's Avatar
    Join Date
    Aug 2003
    Location
    Oslo, Norway. Mhz:4700 x4
    Posts
    1,333

    Re: Automatically Wake Up The Computer From Hibernation [VB6] [Win2000 or later]

    Quote Originally Posted by zahadumy
    VB 6? Can you convert it to .NET?
    No, but you know you can if you try
    Zeegnahtuer?

  6. #6
    Addicted Member zahadumy's Avatar
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    187

    Re: Automatically Wake Up The Computer From Hibernation [VB6] [Win2000 or later]

    Quote Originally Posted by thegreatone
    No, but you know you can if you try
    I have never wrote a single code line in VB 6. I started with VB .NET 2003 and now I'm using VB 2005. So, I won't do that... Your code is really great if it works (and I'm sure it does) but I won't install VB6 just to use it...
    Cheers!
    The first step in solving a problem is to define the problem clearly.

    -----
    Icons | EZIconConverter | Popup Messages
    101 samples: 2003 2005
    Code converter: C# -> VB .NET | VB .NET -> C# | VB .NET <-> C#


    -----
    Visual Studio 2005/.NET Framework 2.0

  7. #7

    Thread Starter
    PoorPoster iPrank's Avatar
    Join Date
    Oct 2005
    Location
    In a black hole
    Posts
    2,728

    Re: Automatically Wake Up The Computer From Hibernation [VB6] [Win2000 or later]

    Sorry, I don't know VB.NET.
    I tried to convert it with VB2005 built-in converter, but it gave me some nasty exceptions.
    Usefull VBF Threads/Posts I Found . My flickr page .
    "I love being married. It's so great to find that one special person you want to annoy for the rest of your life." - Rita Rudner


  8. #8
    Fanatic Member
    Join Date
    May 2005
    Posts
    528

    Re: Automatically Wake Up The Computer From Hibernation [VB6] [Win2000 or later]

    i know that the code to hibernate it is: Timer1.Enabled = True but whats the code to wake up?

  9. #9

    Thread Starter
    PoorPoster iPrank's Avatar
    Join Date
    Oct 2005
    Location
    In a black hole
    Posts
    2,728

    Re: Automatically Wake Up The Computer From Hibernation [VB6] [Win2000 or later]

    The Wait procedure in modTimer is used to 'wakeup'. What it basically does is, it calls the SetWaitableTimer API. The last parameter of the API (fResume) tells it, wheather it will wakeup the system when the timer event occurs or not. (please read 1st link in 1st post for explanation).

    SetSystemPowerState: This API initiates a hibernation.

    The Timer1 just gives us one second so that we can have enough time to set the timer from Wait procedure before the system hibernates. This timer will wakeup our system.

    Please read the How it works ? part in the first post and the linked pages and ask me if you need any more explanation.
    Usefull VBF Threads/Posts I Found . My flickr page .
    "I love being married. It's so great to find that one special person you want to annoy for the rest of your life." - Rita Rudner


  10. #10
    coder. Lord Orwell's Avatar
    Join Date
    Feb 2001
    Location
    Elberfeld, IN
    Posts
    7,621

    Re: Automatically Wake Up The Computer From Hibernation [VB6] [Win2000 or later]

    I am confused. You are using hibernate and suspend interchangeably. Which does it do?
    My light show youtube page (it's made the news) www.youtube.com/@artnet2twinkly
    Contact me on the socials www.facebook.com/lordorwell

  11. #11

    Thread Starter
    PoorPoster iPrank's Avatar
    Join Date
    Oct 2005
    Location
    In a black hole
    Posts
    2,728

    Re: Automatically Wake Up The Computer From Hibernation [VB6] [Win2000 or later]

    Hibernate (and wakeup).
    Usefull VBF Threads/Posts I Found . My flickr page .
    "I love being married. It's so great to find that one special person you want to annoy for the rest of your life." - Rita Rudner


  12. #12
    Hyperactive Member
    Join Date
    Apr 2004
    Location
    Philippines
    Posts
    285

    Re: Automatically Wake Up The Computer From Hibernation [VB6] [Win2000 or later]

    hi there, i know this is already an old post but this seems to be useful on the application im doing. just wanna ask, if the pc is on a "hibernate" stage, can i wake it up using Wake on Lan? because i already have the WOL function working for my client-server app. and i wanted to add the "hibernate" function on my client app.

  13. #13
    Frenzied Member thegreatone's Avatar
    Join Date
    Aug 2003
    Location
    Oslo, Norway. Mhz:4700 x4
    Posts
    1,333

    Re: Automatically Wake Up The Computer From Hibernation [VB6] [Win2000 or later]

    Yes, you can indeed, this is the intended functionality for such a thing.

    WOL will attempt to wake the PC, even when in hibernation.
    Zeegnahtuer?

  14. #14
    Hyperactive Member
    Join Date
    Apr 2004
    Location
    Philippines
    Posts
    285

    Re: Automatically Wake Up The Computer From Hibernation [VB6] [Win2000 or later]

    i see. so, during hibernation, what happens to my app? i have an application that connects to a server app thru winsock. will the connection get lost when the PC hibernates?

  15. #15
    Frenzied Member thegreatone's Avatar
    Join Date
    Aug 2003
    Location
    Oslo, Norway. Mhz:4700 x4
    Posts
    1,333

    Re: Automatically Wake Up The Computer From Hibernation [VB6] [Win2000 or later]

    he connection will most likely be lost, however, it shouldn't be that difficult to bring that connection back up when the PC is back in an "awake" state, this could be done by checking the winsocks connection status.
    Zeegnahtuer?

  16. #16
    Hyperactive Member
    Join Date
    Apr 2004
    Location
    Philippines
    Posts
    285

    Re: Automatically Wake Up The Computer From Hibernation [VB6] [Win2000 or later]

    i see. okies, thanks for the reply. i'll play with this later when i get home i looked at the code and i was confused on how it sets the PC to hibernate. so i researched the net and found out about SetSystemPowerState() API

  17. #17
    Junior Member
    Join Date
    Jul 2007
    Posts
    18

    Re: Automatically Wake Up The Computer From Hibernation [VB6] [Win2000 or later]

    great job iPrank!,

    I plan to use your code on my PC to see if it works. I'm somewhat descent with .NET and will attempt to recode it. If successful, I'll post it back on here for ya.

  18. #18
    New Member
    Join Date
    Oct 2008
    Posts
    1

    Re: Automatically Wake Up The Computer From Hibernation [VB6] [Win2000 or later]

    hi dude....

    im very much thankful to u........

    hope u il help me out soon

  19. #19
    New Member
    Join Date
    Nov 2008
    Posts
    1

    Re: Automatically Wake Up The Computer From Hibernation [VB6] [Win2000 or later]

    Quote Originally Posted by iPrank
    The Story:

    I was looking for a alarm clock software that will wake me up at 6:00am so that I can start spaming here at VBF as soon as possible. But I don't want to keep my PC turned on all night.
    Many modern motherboards supports automatic boot-up alarm. But my motherboard doesn't. 'Wake on LAN' may be an option, but I don't have a LAN. 'Wake on Modem Ring' may be another option, but I gave my dial-up modem to my friend.
    So, here is my workaround: Keep the PC in Hibernate (Suspend) mode and wake it up at 6:00am.

    The Program:

    This program simply puts the PC in hibernation state and wakes it up at a pre-defined time. Optionally it can sound an alarm when it wakes up. (You must keep the power on. )

    Before We Begin:

    1.) This works only in Win2000 or later
    2.) Make sure your motherboard supports ACPI S4 state.
    2.) Make sure hibernation is enabled in Windows. Go to, ControlPanel>PowerOptions and in the 'Hibernation' tab, check the 'Enable hibernation' checkbox.

    Enter the Coder:

    Open the project in VB and run it. Press the 'Test' button.
    If everything is ok, your system will go to Hibernation. Don't turn off power. Your system will wake up automatically after 2 minutes.
    If your system doesn't wake up within 3-4 minutes, press the power button of your computer.

    Note: Hibernation is very much OS/Motherboard/DeviceDriver dependent. Make sure Windows can hibernate your computer perfectly. Save all work before testing.

    How it works ?

    Basically I have done nothing but merging the following codes:
    How To Use SetWaitableTimer With Visual Basic
    SetSystemPowerState

    SetSystemPowerState initiates a hibernation and just then, CreateWaitableTimer and SetWaitableTimer creates and sets a waitable timer with passing True to the fResume parameter. When the timer event fires, Windows automatically wakes-up.

    In addition, I have subclassed the form. When Windows or any other program tries to suspend the system, I'm discarding the operation and initiating my own Hibernate&WakeUp routine. (Will be useful if we keep it running in background or in systray. In v2.0 may be. )

    End Sub:
    I have tested this code on Windows 2003 Server and it is working ok.
    Special thanks to fahad k for testing this code.

    This is my first codebank submission. Please feel free to comment or slap me.
    Hi,

    I gone thorugh you r example. I need to wake up my machine by setting time. My scenario is, 10 am i want to switch on. 01:00 pm stand by and 2pm wake up. 4 pm stand by. 6 wake up. for this purpose we can use timer control. From ur example i tried. but its not diaplying the form whn i set time to wake up. wht to do

  20. #20
    coder. Lord Orwell's Avatar
    Join Date
    Feb 2001
    Location
    Elberfeld, IN
    Posts
    7,621

    Re: Automatically Wake Up The Computer From Hibernation [VB6] [Win2000 or later]

    well i finally see how this works. I was under the impression that hibernate shuts the system off. Turns out it doesn't. It does however turn off the ram.
    My light show youtube page (it's made the news) www.youtube.com/@artnet2twinkly
    Contact me on the socials www.facebook.com/lordorwell

  21. #21
    New Member
    Join Date
    Oct 2009
    Posts
    2

    Re: Automatically Wake Up The Computer From Hibernation [VB6] [Win2000 or later]

    Quote Originally Posted by psenthil_17 View Post
    Hi,

    I gone thorugh you r example. I need to wake up my machine by setting time. My scenario is, 10 am i want to switch on. 01:00 pm stand by and 2pm wake up. 4 pm stand by. 6 wake up. for this purpose we can use timer control. From ur example i tried. but its not diaplying the form whn i set time to wake up. wht to do
    I also want to know, thank you.

  22. #22
    New Member
    Join Date
    Mar 2009
    Posts
    3

    Re: Automatically Wake Up The Computer From Hibernation [VB6] [Win2000 or later]

    I know its very old thread... I just want to say.. kudos to iPrank.

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