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.
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.
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.
Re: Automatically Wake Up The Computer From Hibernation [VB6] [Win2000 or later]
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.
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.
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.
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?
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.
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
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.
Re: Automatically Wake Up The Computer From Hibernation [VB6] [Win2000 or later]
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.
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
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.
Re: Automatically Wake Up The Computer From Hibernation [VB6] [Win2000 or later]
Originally Posted by psenthil_17
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