Shut Down Windows

A software for automatic shutdown of windows system.

Posted by Dusign on 2019-10-19
Words 875 and Reading Time 3 Minutes
Viewed Times

现在的生活离不开电脑,很多时候我们都需要电脑定时关机,笔者也不例外,对于懂 DOS 命令的人来说直接使用 shutdown 命令就可以解决这个问题,但是每次输入这个命令有点烦,所以笔者为了方便写了一个简易的自动关机的程序,现分享出来,内容比较简单,其实就是用了 DOS 命令。

界面没有进行美化,有点丑,如果你觉得不好看的话可以自己写一个好看的界面,有什么问题欢迎到评论区留言。

代码展示

主要代码如下

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<windows.h>
#include<time.h>
int print(){
printf(" ------- 定时关机程序 -------\n");
printf(" + 1 定时关闭计算机 +\n");
printf(" + 2 立即关闭计算机 +\n");
printf(" + 3 注销计算机 +\n");
printf(" + 4 取消关机计划 +\n");
printf(" + 0 退出系统 +\n");
printf(" ----------------------------\n");
return 0;
}
int main(){

// Set terminal properties
system("color f3");
system("定时关机程序");
system("mode con cols=32 lines=24");

// display system time
time_t tm = time(0);
char temp[64];
printf("\n");
strftime(temp,sizeof(temp)," %Y/%m/%d %X %A \n",localtime(&tm));
puts(temp);

// shutdown
char cmd[30]="shutdown -s -t ";
char t[4]="0";
print();
int c,num;
float tmp;
printf(" 请选择功能类型:");
scanf("%d",&c);
switch(c){
case 1:
printf(" 您想在多少小时后自动关机:");
scanf("%f",&tmp);
num=tmp*60*60;
itoa(num,t,10);
system(strcat(cmd,t));
tm=tm+num;
// Operation result promptness
printf("\n");
strftime(temp,sizeof(temp)," 您的电脑将在 %X 关机 \n",localtime(&tm));
puts(temp);
break;
case 2:system("shutdown -p");break;
case 3:system("shutdown -l");break;
case 4:system("shutdown -a");break;
case 0:break;
default:printf("Error!\n");
}
system("pause");
exit(0);
}

下载链接

双击 shutdown.ext,运行如下图,选择你需要的功能,按照提示输入 ,然后 enter 就行
shutdown
如果想下载编译之后的程序,请点击 shutdown.exe 下载,得到 shutdown.zip 文件,解压之后双击 shutdown.exe 即可运行。

Shutdown命令

命令:Shutdown

作用:允许您关闭或重新启动本地或远程计算机。如果没有使用参数,shutdown 将注销当前用户。

语法:shutdown [{-l|-s|-r|-a}] [-f] [-m [\\ComputerName]] [-t xx] [-c "message"] [-d[u][p]:xx:yy]

参数:

  • -l
    注销当前用户,这是默认设置。-m ComputerName 优先。

  • -s
    关闭本地计算机。

  • -r
    关闭之后重新启动。

  • -a
    中止关闭。除了 -l 和 ComputerName 外,系统将忽略其它参数。在超时期间,您只可以使用 -a。

  • -f
    强制运行要关闭的应用程序。

  • -m [\\ComputerName]
    指定要关闭的计算机。

  • -t xx
    将用于系统关闭的定时器设置为 xx 秒。默认值是 20 秒。

  • -c "message"
    指定将在“系统关闭”窗口中的“消息”区域显示的消息。最多可以使用 127 个字符。引号中必须包含消息。

  • -d [u][p]:xx:yy
    列出系统关闭的原因代码。下表将列出不同的值。

  • /?
    在命令提示符显示帮助。

其中:u为指定用户代码;p为指定已计划的关闭代码;xx为指定主要原因代码 (0-255);yy为指定次要原因代码 (0-65536)。

一旦指定了主要和次要原因代码,您必须首先为计划使用某种特定原因的每个计算机定义那些原因代码。如果目标机器上没有定义原因代码,则事件查看器无法记录正确的原因文本。


If you like this blog or find it useful for you, you are welcome to comment on it. You are also welcome to share this blog, so that more people can participate in it. If the images used in the blog infringe your copyright, please contact the author to delete them. Thank you !

...

...

00:00
00:00