C语言实现电脑关机程序

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/XiaoCaiDaYong/article/details/89235753

这个是我在网上搜索到的资料,其实也是很简单的。

想使用ESP8266完成这样一个操作——远程关闭电脑,达到人在别的任何地方都可以操作我们的电脑。

这个虽然已经不是羡慕新奇的事,实现的方法也撑出不穷,但我们学习ESP8266,也不失是一种体验的过程。

对于初学者来说也是一种很有成就感的体验。

因此,想完成远程关机,就需要理解怎么实现关机的命令及程序,我们使用C语言来完成。

串口助手也可以实现,但串口助手毕竟是为了调式用的,并不适合应用使用。

代码如下:

//#include "stdafx.h"
#include "stdio.h"
#include "string.h"
#include "stdlib.h"
int print()
{
	printf(" ╪╪╪╪╪╪╧╧╧╧╧╧╧╧╪╪╪╪╪╪\n");
	printf("╔═══╧╧ C语言 关机程序 ╧╧═══╗\n");
	printf("║※1.实现10分钟内的定时关闭计算机 ║\n");
	printf("║※2.立即关闭计算机 ║\n");
	printf("║※3.注销计算机 ║\n");
	printf("║※0.退出系统 ║\n");
	printf("╚═══════════════════╝\n");
	return 0;
}
int main()
{
	char cmd[20]="shutdown -s -t ";
	char t[5]="0";
	int c;
	system("title C语言关机程序");//设置cmd窗口标题
	system("mode con cols=48 lines=25");//窗口宽度高度
	system("color 0B");
	system("date /T");
	system("TIME /T");	
	print();	
	scanf("%d",&c);
	getchar();
	switch(c)
	{
		case 1:printf("您想在多少秒后自动关闭计算机?(0~600)\n");scanf("%s",t);system(strcat(cmd,t));break;
		case 2:system("shutdown -p");break;
		case 3:system("shutdown -l");break;
		case 0:break;
		default:printf("Error!\n");
	}
	system("pause");
	exit(0);
}

我运行的环境为:VC++6.0

运行效果如下:

选择2,回车后的效果:

这样就完成了C语言实现电脑关机的过程。

接下来要完成:通过ESP8266模块实现手机远程关闭电脑。

猜你喜欢

转载自blog.csdn.net/XiaoCaiDaYong/article/details/89235753
今日推荐