首页 > 系统相关 >Windows定时关机小程序

Windows定时关机小程序

时间:2023-02-02 21:33:24浏览次数:37  
标签:关机 arr Windows char second printf 定时 minutes

整理文件发现以前写的定时关机小程序(Windows下)

1-效果

 

2-程序

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

int main() {
	//界面
	printf("-------自动关机小程序-------\n");
	printf("您想在几分钟后关机?请输入正整数:");
	//定义变量
	unsigned long long second;
	unsigned int minutes;
	char charsecond[100] = {};
	char arr[100] = {};
	char cmd[20] = "shutdown -s -t ";
	char input[20];
	scanf("%d", &minutes); //读取分钟数
	second = 60 * minutes; //计算秒数
//	printf("%d\n", second);
	itoa(second, charsecond, 10); //将数字转化为字符串
	strcpy(arr, strcat(cmd, charsecond));
	system(arr);//执行关机命令
//	printf("%s%s", arr, "\n");
	printf("系统将于%d分后关机,输入“stop”可取消关机\n", minutes);

	while (1) {
		scanf("%s", input);
		if (0 == strcmp(input, "stop")) {
			system("shutdown -a");
			printf("关机操作已经被取消\n");
			printf("5秒后程序自动关闭,倒计时:\n");
			int i;
			for (i = 5; i > 0; i--) {
				printf("%d ", i);
				sleep(1);
			}
			break;
		} else {
			printf("关机继续\n");

		}

	}
	return 0;
}

 

标签:关机,arr,Windows,char,second,printf,定时,minutes
From: https://www.cnblogs.com/FishSmallWorld/p/17087491.html

相关文章

  • Linux基础:文件相关信息、文件索引信息、链接信息、系统时间、机器克隆、定时任务、par
    目录一、文件相关信息二、文件索引信息三、链接信息四、系统时间五、机器克隆六、定时任务七、paramiko模块八、公钥私钥九、paramiko其他操作十、代码封装十一、面试题回......
  • Gitea安装在Windows 10:自用
    Windows10gitversion2.33.1.windows.1gitea-1.18.3-- 用过一些代码管理工具:SVN、Gogs、Gitlab,最近听说了一个叫Gitea的,试试。ben发布于博客园 需提前安装好......
  • 适用于 Linux 的 Windows 子系统使用 Visual Studio Code
    在WSL中使用VSCode,先在Windows中安装vscode,再通过功能扩展安装Vscodeforwsl。VSCode有system和user两个版本,默认下载链接为user版本。以下内容为system版本。......
  • [转]windows下redis的下载安装
    参考文章地址:1.http://m.biancheng.net/redis/windows-installer.html2.https://www.cnblogs.com/yyee/p/15835952.html 下载地址:Releases·tporadowski/redis(g......
  • windows常用dns相关命令
    ipconfig/displaydns查询当前DNS缓存   ipconfig/flushdns清空本机缓存   互联网上常见的公共DNS服务器的IP地址如下:首选DNS服务器地址 备用D......
  • VMware Workstation Pro16安装Windows11
    报错:这台电脑无法运行Windows11解决方法设置窗口,设置访问控制密码添加可信任模块配置完成再启动虚机即可......
  • Windows启动问题修复(重建活动分区)
      本教程说明如何在当Windows系统无法正常启动时,采取重建活动分区的方式来尝试修复,目的在于不使用第三方软件和不重装系统的前提下对系统启动问题进行最小代价修复。 ......
  • 将Windows系统设置为NTP服务器
    环境Windows10,本机IP地址为:192.168.6.133步骤一、编辑注册表win+r快捷键打开运行窗口,输入regedit打开注册表编辑器,找到以下几项并修改其值:1、将type的值修改为NTP:HK......
  • [转]windows下nacos的配置使用
    原文地址:NacosWindows版本安装-简书(jianshu.com)1.从github下载zip,地址:https://github.com/alibaba/nacos/releases2.解压,执行conf目录的sql文件建立需要用到......
  • 查看电脑开关机时间
    在我们的生活和工作中都离不开电脑,而为了更好的管理电脑,我们就需要知道电脑的开关机时间,那么这要去哪看呢?下面小编在计算机管理器上操作,来查看电脑开关机时间。先在“此......