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.
Table of contents
〇、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.
The timer shutdown is set successfully!
Input 1 to cancel shutdown
Cancel shutdown successfully!