PDA

Click to See Complete Forum and Search --> : Automatically Wake Up The Computer From Hibernation [VB6] [Win2000 or later]


iPrank
Mar 30th, 2006, 11:35 AM
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. :D 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. :p)

Before We Begin:

1.) This works only in Win2000 or later
2.) Make sure your motherboard supports ACPI (http://en.wikipedia.org/wiki/Advanced_Configuration_and_Power_Interface) 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 (http://support.microsoft.com/kb/q231298/)
SetSystemPowerState (http://www.mentalis.org/apilist/SetSystemPowerState.shtml)

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. :)

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. :D)

End Sub:
I have tested this code on Windows 2003 Server and it is working ok.
Special thanks to fahad k (http://www.vbforums.com/member.php?userid=66130) for testing this code. :thumb:

This is my first codebank submission. Please feel free to comment or slap me. :D

I_Love_My_Vans
Mar 30th, 2006, 03:33 PM
Hell yea!!! well im guessing that, but i have been looking for smmurt like this. well played

ILMV

iPrank
Mar 31st, 2006, 02:04 AM
Thanks dude. :D

I have tested this in my friends' PC, WinXP-SP2, and it works there too.

zahadumy
Apr 25th, 2006, 06:42 PM
VB 6? Can you convert it to .NET? :D

thegreatone
Apr 25th, 2006, 07:10 PM
VB 6? Can you convert it to .NET? :D
No, but you know you can if you try ;)

zahadumy
Apr 25th, 2006, 07:36 PM
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!

iPrank
May 5th, 2006, 10:43 AM
Sorry, I don't know VB.NET.
I tried to convert it with VB2005 built-in converter, but it gave me some nasty exceptions. :(

killo
Jan 21st, 2007, 06:35 AM
i know that the code to hibernate it is: Timer1.Enabled = True but whats the code to wake up?

iPrank
Jan 21st, 2007, 09:59 AM
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.

Lord Orwell
Jul 9th, 2007, 04:38 PM
I am confused. You are using hibernate and suspend interchangeably. Which does it do?

iPrank
Jul 9th, 2007, 07:34 PM
Hibernate (and wakeup).

guyjasper
Jan 27th, 2008, 10:06 PM
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.

thegreatone
Jan 28th, 2008, 02:35 AM
Yes, you can indeed, this is the intended functionality for such a thing.

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

guyjasper
Jan 29th, 2008, 01:43 AM
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?

thegreatone
Jan 29th, 2008, 03:17 AM
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.

guyjasper
Jan 29th, 2008, 03:36 AM
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 ;)

mykewall
Feb 6th, 2008, 08:40 AM
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.

abi_allan
Oct 20th, 2008, 02:04 PM
hi dude....

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

hope u il help me out soon:afrog:

psenthil_17
Nov 24th, 2008, 12:07 AM
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. :D 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. :p)

Before We Begin:

1.) This works only in Win2000 or later
2.) Make sure your motherboard supports ACPI (http://en.wikipedia.org/wiki/Advanced_Configuration_and_Power_Interface) 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 (http://support.microsoft.com/kb/q231298/)
SetSystemPowerState (http://www.mentalis.org/apilist/SetSystemPowerState.shtml)

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. :D)

End Sub:
I have tested this code on Windows 2003 Server and it is working ok.
Special thanks to fahad k (http://www.vbforums.com/member.php?userid=66130) for testing this code. :thumb:

This is my first codebank submission. Please feel free to comment or slap me. :D
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

Lord Orwell
Nov 24th, 2008, 08:19 AM
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.

magicsoft
Oct 3rd, 2009, 10:48 PM
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.

Chanakya69
Apr 11th, 2010, 08:55 PM
I know its very old thread... I just want to say.. kudos to iPrank.