Is there a C++ function to turn off the computer? And since I doubt there is one (in the standard library, at least), what's the windows function that I can call from C++?
是否有C ++功能关闭计算机?既然我怀疑有一个(至少在标准库中),我可以用C ++调用什么是windows函数?
Basically, what is the code to turn off a windows xp computer in c++?
基本上,在c ++中关闭windows xp计算机的代码是什么?
5 个解决方案
#1
On windows you can use the ExitWindows function described here:
在Windows上,您可以使用此处描述的ExitWindows函数:
http://msdn.microsoft.com/en-us/library/aa376868(VS.85).aspx
and here's a link to example code that does this:
这是一个指向示例代码的链接:
http://msdn.microsoft.com/en-us/library/aa376871(VS.85).aspx
#2
Use the following, assuming you have the privileges):
假设您拥有以下权限,请使用以下命令:
ExitWindowsEx (EWX_POWEROFF | EWX_FORCEIFHUNG,
SHTDN_REASON_MINOR_OTHER);
This will cause power off while giving applications a chance to shut down (if they take too long, they'll be terminated anyway).
这将导致电源关闭,同时给应用程序关闭的机会(如果它们花费太长时间,它们将被终止)。
It's part of the Win32 API rather than standard C++ but that's because C++ provides no way to do this directly.
它是Win32 API的一部分,而不是标准的C ++,但这是因为C ++无法直接执行此操作。
#3
You can shutdown by utilizing the system() function.
您可以使用system()函数关闭。
for Windows
system("shutdown -s");
for Linux
system("poweroff");
or
system("init 0");
#4
You can do this in Windows, by calling the ExitWindowsEx
function.
您可以通过调用ExitWindowsEx函数在Windows中执行此操作。
#5
yes! for Windows XP:
是!对于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;
}
For Windows 7
对于Windows 7
system("C:\\WINDOWS\\System32\\shutdown /s");
For Linux
system("shutdown -P now");
#1
On windows you can use the ExitWindows function described here:
在Windows上,您可以使用此处描述的ExitWindows函数:
http://msdn.microsoft.com/en-us/library/aa376868(VS.85).aspx
and here's a link to example code that does this:
这是一个指向示例代码的链接:
http://msdn.microsoft.com/en-us/library/aa376871(VS.85).aspx
#2
Use the following, assuming you have the privileges):
假设您拥有以下权限,请使用以下命令:
ExitWindowsEx (EWX_POWEROFF | EWX_FORCEIFHUNG,
SHTDN_REASON_MINOR_OTHER);
This will cause power off while giving applications a chance to shut down (if they take too long, they'll be terminated anyway).
这将导致电源关闭,同时给应用程序关闭的机会(如果它们花费太长时间,它们将被终止)。
It's part of the Win32 API rather than standard C++ but that's because C++ provides no way to do this directly.
它是Win32 API的一部分,而不是标准的C ++,但这是因为C ++无法直接执行此操作。
#3
You can shutdown by utilizing the system() function.
您可以使用system()函数关闭。
for Windows
system("shutdown -s");
for Linux
system("poweroff");
or
system("init 0");
#4
You can do this in Windows, by calling the ExitWindowsEx
function.
您可以通过调用ExitWindowsEx函数在Windows中执行此操作。
#5
yes! for Windows XP:
是!对于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;
}
For Windows 7
对于Windows 7
system("C:\\WINDOWS\\System32\\shutdown /s");
For Linux
system("shutdown -P now");