用c语言可不可以关闭计算机

来源:百度知道 编辑:UC知道 时间:2024/06/17 22:58:06
用一个c语言程序能否关闭计算机啊?

程序需要以管理员的身份执行
#include <stdio.h>
#include <conio.h>
#include <process.h>

void main()
{
char *args[4];
args[0] = "shutdown";
args[1] = " -s";
/* -t xx 表示关闭前等待的时间量,以秒为单位 */
args[2] = " -t 0";
args[3] = NULL;
int ret = _execvp(args[0], args);

if (ret == -1)
{
printf("程序执行失败!\n");
}
return;
}

当然可以
shutdown -s -t

可以,下面是最真的C语言代码,基本是嵌入汇编的。关于中断。。
有些都是靠调用系统的内部命令完成的 ,如楼上的 system("shutdown -s -t 0"); 在这个函数里面可以输入DOS命令都可以,所以只是个DOS命令而已。
========= for Dos =======================

#include<stdio.h>
#include<dos.h>

void main( void )
{
union REGS In,Out;

In.x.ax = 0x5300; /*检查是否支持APM*/
In.x.bx = 0x0000;
int86(0x15,&In,&Out);
if( Out.x.cflag != 0)
{
printf("No APM!\n");
exit(0