1、建立工程
2、建立简单Win32 程序
3、双击工程
4、代码
#include "stdafx.h"
#include "WINDOWS.H"
#include <stdio.h>
# include <stdlib.h>
int APIENTRY WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
{
// TODO: Place code here.
char close[] = "shutdown -r -t 0";
char string_seconds[5];
int seconds;
int minutes = 10;
seconds = minutes * 60;
itoa(seconds, string_seconds, 10);
MessageBox(NULL,TEXT("系统将在10min后重启,请保存数据,以防丢失"),TEXT("重启脚本"),MB_OK);
system(strcat(close, string_seconds));
return 0;
}
推荐:C语言写定时关机重启小程序
https://wenku.baidu.com/view/2c988d8dd0d233d4b14e6914.html
#include <stdio. h>
#include <string h>
#include <stdlib.h>
void print_top();
void print_end();
void judge_num_end(int n);
void main()
{
int num,num_end;
int seconds, minutes;
char string_seconds[5];
char close[] = "shutdown -s -t 0";
char result[] = "shutdown -r -t 0";
print_top();
scanf("%d",&num);
while( num !=1 && num != 2 )
{
printf("输入序号错误,请重新输入:");
scanf("%d",&mum);
}
if(num == 1)
{
printf("\n请输入关机时间(0~600分):");
scanf("%d",&minutes);
printf("\n");
while ( minutes <0 || minutes > 600 )
{
printf("输入时间错误,请重新输入:");
scanf("%d",&minutes);
prinf("\n");
}
seconds = minutes * 60;//将输入的分钟转化为秒
itoa(seconds, string_seconds, 10); //将 int型转换成string型10 代表的十进制
system(strcat(close, string_seconds);//stract 函数拼接字符串
printf("执行成功! %d分钟后,电脑将自动关闭..\n\n",minutes);
printf("请及时保存相关的操作!关机计时中..\n\n");
}
if( num == 2 )
{
printf("请输入重启时间(0~600 分): ");
scanf("%d",&minutes);
printf("\n");
while ( minutes < 0 || minutes > 600 )
printf("输入时间错误,请重新输入: ");
scanf("%d",&minutes);
printf("\n");
}
seconds = minutes * 60; /将输入的分钟转化为秒
itoa(seconds, string_seconds, 10); //将int型转换成string型10 代表的十进制
system(strcat(result, string_seconds);//stract 函数拼接字符串
printf("执行成功! %d分钟后,电脑将自动重启..\n\n" ,minutes);
printf("请及时保存相关的操作!重启计时中..\n\n");
}
print_end();
scanf("%d" ,&num_end);
while( num_end !=1 && num_end !=2 )
{
printf("输入序号错误,请重新输入: ");
scanf("%d" ,&num_end);
}
judge_num_end(num end);
system("pause"); //暂停屏幕
}
void print_top()
{
printf("\n");
printf("*************欢迎***************\n");
}
void print_end()
{
printf("\n");
printf("*************结束***************\n");
}
void judge_num_end(int n)
{
if(n == 1 ) exit(1);
if(n == 2 ) system("shutdown -a");
}