C language programming exercise (8) - cmd control timing shutdown and cancel shutdown

cmd control timing shutdown and cancel shutdown

Tools used: VS2019
Functions:
1. Enter a number to select a function.
2.0 is timed shutdown, 1 is cancel shutdown.


〇、Knowledge Supplement

cmd command:

 shutdown	
	 -l                注销
	 -r                重启
	 -s                关机
	 -a                取消关机
	 -t xxx            设置时间

1. Code part

Function implementation:

//输入一个数字来选择功能,0为定时关机,1为取消关机
void shutdown(int number)
{
    
    
	switch (number)
	{
    
    
	case 0:
		system("shutdown -s -t 3600");			//3600秒后关机
		break;
	case 1:
		system("shutdown -a");					//取消关机
		break;
	default:
		printf("选择功能错误错误!\n");
		break;
	}
}

Main function call:

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

void shutdown(int number);

int main()
{
    
    
	int i = 0;				//选择功能
	printf("输入一个数字来选择功能\n0为定时关机,1为取消关机\n");
	printf("输入0/1来选择功能:\n");
	scanf_s("%d", &i);

	shutdown(i);

	printf("\n");
	system("pause");
	return 0;
}

2. Running results

Enter 0 to turn off the timer.
insert image description here
The timer shutdown is set successfully!
insert image description here

Input 1 to cancel shutdown insert image description here
Cancel shutdown successfully!
insert image description here

Guess you like

Origin blog.csdn.net/weixin_44739914/article/details/112228048