C语言实现关机

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/dark_cy/article/details/88317338
#include  <stdlib.h>
#include  <windows.h>
int main(void)
{
    int iResult = ::MessageBox(NULL,TEXT("确认要关机?"),TEXT("关机"),MB_OKCANCEL|MB_ICONQUESTION );
    if(1 ==iResult )
    {
       system("shutdown -s -t 0");
    }
    return 0;
}

程序运行后会弹出一个对话框,点击确认才会关机
system是标准库的一个函数,用来执行一些外部命令。。
这里shutdown 其实是DOS命令,这里通过system调用它便可关机,而不用那繁杂的 API 。。
shutdown 还可实现定时关机,比如 at 12:00 shutdown -s -t 0 表示在12:00 关机

没有提示的。。。

#include  <stdlib.h>
int main(void)
{
   system("shutdown -s -t 0");
   return 0;
}

猜你喜欢

转载自blog.csdn.net/dark_cy/article/details/88317338