i need to find away to turn on the pc from c++ application , is there any way to do this? Thanks
-
5How will the application run if the computer is off? Or is this a remote machine? – Callum Rogers Sep 22 '11 at 12:35
-
Cannot think of a function that can press the button on the front of the thing or the switch on the wall. – Ed Heal Sep 22 '11 at 12:36
-
Which operating system are you on? There is a function in ACPI to power on the computer at a given time, and there is an option under linux to set this time via /proc/acpi/alarm. I'm not sure how this works under windows though. – jdm Sep 22 '11 at 12:41
-
2You couldn't even bother with capital letters? You've been here for almost 3 years and asked 412 questions, and answered only 2; a _little_ bit of courtesy, please. – Lightness Races in Orbit Sep 22 '11 at 13:03
-
@jdm: The question is tagged `winapi`. – Lightness Races in Orbit Sep 22 '11 at 13:05
-
Right. I always overlook the tags... – jdm Sep 22 '11 at 13:06
-
http://thedailywtf.com/Articles/ITAPPMONROBOT.aspx was used to reset a computer, no reason it couldn't be used to power one on. – IronMensan Sep 22 '11 at 13:31
7 Answers
If the computer is off, it can't be executing code, and therefore can't turn itself on programmatically.
ACPI changes that somewhat, but for us to be able to help, you have to be more specific about your exact requirements.
If you need to turn on a different computer, take a look at Wake-on-LAN.

- 486,780
- 108
- 951
- 1,012
-
That is only partially true, since (I'd guess) 2002 most PCs have ACPI, which allows hardware timers to be set. Even if your computer is 'off', the mainboard actually pulls a small amount of power to power the network card, listen for keyboard input (wake on lan, wake on keyboard, etc.), or wait for a timer. Unfortunately my experience is that this feature was not very reliable when I tried it, but I hope that might have changed by now. – jdm Sep 22 '11 at 13:02
-
I have a timer configured in my PC's BIOS to turn the PC on every weekday at the same time, and it works fine and reliably. – Remy Lebeau Sep 22 '11 at 20:13
You will not be able to write a program to turn a computer on that the program itself is installed on.
If you need to write an application that will turn on a different computer, Wake-on-LAN is the tool for you. Modern desktops have NICs that is always receiving power - even if the computer is in an S5 state. Assuming the BIOS supports it and it is enabled.
Wake-On-LAN works by sending a Magic Packet to the NIC. The details of what the payload consists of is outlined in the article.

- 138,677
- 31
- 291
- 286
This is possibly a duplicate of C#: How to wake up system which has been shutdown? (although that is C#).
One way to do it under windows is to create a timer with CreateWaitableTimer()
, set the time with SetWaitableTimer()
and then do a WaitForSingleObject()
. Your code will pause, and you can put the computer into standby (maybe also hibernation, but not shutdown). When the timer is reached, the PC will resume and so will your program.
See here for a complete example in C. The example shows how to calculate the time difference for the timer, and how to do the waiting in a thread (if you are writing a graphical application).
I have to add, you can also schedule the computer to wake up using the Windows Task Scheduler ('Wake the computer to run this task'). This possibly also works when the computer is shut down. There is also an option in some computers BIOS to set a wake time.
Under Linux, you can set the computer to wake up by writing to a special file:
echo 2006-02-09 23:05:00 > /proc/acpi/alarm
Note that I haven't tested all of this, and it is highly dependent on the hardware (mainboard), but some kind of wake-up should be available on all modern PCs.
See also: http://en.wikipedia.org/wiki/Real-time_clock_alarm , and here is a program that claims to do it on windows: http://www.dennisbabkin.com/wosb/
-
1CreatewaitableTimer is the correct answer. Set the fResume argument to SetWaitableTimer to TRUE. – Hans Passant Sep 22 '11 at 13:32
Use strip
. If you require a Windows computer to be turned on, the cross-tools i686-w64-mingw32-strip
or x86_64-w64-mingw32-strip
should be used. These command-line programs modify an executable, and the result is able to turn on a computer.

- 35,651
- 4
- 70
- 100
How could you turn on a computer from an application, when no processes are running on it when it's shut down ? You can turn on another computer (Wake on Lan), but not the one you are running.

- 6,808
- 10
- 44
- 75
It is possible.
First thing to do is configure Wake On Lan. Check out this post on Lifehacker on how to do it: http://lifehacker.com/348197/access-your-computer-anytime-and-save-energy-with-wake+on+lan.
(Or this link: http://hblg.info/2011/08/21/Wake-on-LAN-and-remote-login.html)
Then you need to send a magic packet from your C++ application. There are several web services that already do this from javascript (wakeonlan.me) , but it can be done from within a C++ application as well.

- 37,072
- 9
- 60
- 86
Chances are, that if you want to do this, you are working with servers. In such case, your mainboard may should an IMPI baseboard management controller. IPMI may be used to cycle the chassis power remotely. Generally, the BMC will have its own IP address, to which you may connect to send control messages.

- 1