Is there a C ++ function to shut down a computer?

Is there a C ++ function to shut down a computer? And since I doubt that there is one (in the standard library, at least), what is the windows function that I can call from C ++?

Basically, what is the code to shut down a Windows XP computer in C ++?

+2
source share
5 answers

In windows, you can use the ExitWindows function described here:

http://msdn.microsoft.com/en-us/library/aa376868(VS.85).aspx

and here is a link to sample code that does this:

http://msdn.microsoft.com/en-us/library/aa376871(VS.85).aspx

+18
source

Use the following if you have privileges):

ExitWindowsEx (EWX_POWEROFF | EWX_FORCEIFHUNG,
    SHTDN_REASON_MINOR_OTHER);

, ( , ).

API Win32, ++, , ++ .

+4

, system().

Windows

system("shutdown -s");

Linux

system("poweroff");

system("init 0");
+3

Windows, ExitWindowsEx.

+2

! Windows XP:

#include <stdio.h>
#include <stdlib.h>

int main()
{
   char ch;

   printf("Do you want to shutdown your computer now (y/n)\n");
   scanf("%c", &ch);

   if (ch == 'y' || ch == 'Y')
       system("C:\\WINDOWS\\System32\\shutdown -s");
       return 0;
}

Windows 7

system("C:\\WINDOWS\\System32\\shutdown /s");

Linux

system("shutdown -P now");
0

Source: https://habr.com/ru/post/1719007/


All Articles