R
R
Recardo_Recoly2017-03-20 21:31:23
C++ / C#
Recardo_Recoly, 2017-03-20 21:31:23

How to turn off the PC using C?

How to turn off a PC without using Windows libraries and so on. (OS no)
That is, there is a program that is loaded instead of Windows (from a USB flash drive (if you select a bootable USB flash drive in the BIOS (not a hack!))).
Shows some data and by pressing enter it should turn off the PC.
I found such a code, but it reboots the PC (everything I found either does not work or reboots).

void stop()
{
     asm volatile("mov $0x5307, %ax; xor %bx, %bx; inc %bx; mov $3, %cx; int $0x15;");
}

Help me please.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
M
Maxim Moseychuk, 2017-03-20
@fshp

Remember the days of windows 98? "You can now power off your computer"
Windows could not power off your computer because it did not support ACPI or another power management interface.
There is no "turn off the computer" command, it happens just the same through ACPI. How it is implemented - refer to the documentation of the motherboard manufacturer and the ACPI specification (or APM if the board is very old).

D
Dmitry, 2017-03-20
@TrueBers

So you do not find the code with mindless copying it to the source, but figure out how it works, what are the interfaces for power management. Make sure what interfaces your system supports, bios.
Google APM power off, or ACPI global state G2 (or sleep state S5).
The first is simpler, but ancient and is not supported in practice, in favor of the second. The second is more modern, but very complex and more functional.
And you have some piece of APM, torn out of nowhere. Why do you think he should earn?
Open the source of any modern OS, and see how it's done. Everything is much more complicated than just 5 teams.

K
Konstantin Tsvetkov, 2017-03-20
@tsklab

everything I found either does not work
So turning off the computer is a special privilege, not everyone deserves it.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question