吾爱破解 - LCG - LSG |安卓破解|病毒分析|www.52pojie.cn

 找回密码
 注册[Register]

QQ登录

只需一步,快速开始

查看: 12359|回复: 60
收起左侧

[原创工具] 【原创】倒计时自动关机&重启&注销

  [复制链接]
fissssssh 发表于 2019-2-3 14:10
本帖最后由 1060096267 于 2019-2-3 20:37 编辑

最近在玩刀塔自走棋,每次玩完本本都烫啊,又是深夜,就想着让它多散一会热再关机
但是我又不想守着,就写了个小工具。

工具使用C#编写,绿色
  

图标

图标

  

主界面

主界面


原理:调用cmd.exe执行shutdown命令

链接:http://r.virscan.org/language/zh-cn/report/913dba1595a63cfecdb2a9a7f329b108
     https://habo.qq.com/file/showdetail?md5=96e66be22c059c542bac873360e01fbf&pk=ADQGb11qB2AIMVs6U2A%3D


2019年2月3日17:45:42 该工具需要 Microsoft .NET Framework 4.0 框架 没有框架的同学可以去微软官网下载:https://www.microsoft.com/zh-CN/download/details.aspx?id=17851
2019年2月3日20:36:07 链接更新:https://www.lanzouj.com/i32h58f 密码:egjb(由于之前没注意,附件放成了最初版本)
最后附上源码: WindowsFormsApp3.rar (344.19 KB, 下载次数: 147) 解压密码:52pojie.cn
[C#] 纯文本查看 复制代码
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace WindowsFormsApp3
{
    //操作类型
    public enum Operation
    {
        Shutdown, Reboot, Logout, Cancel
    }

    public partial class Form1 : Form
    {
        private string error = "";
        private int countDown = 0;
        private bool isCount = false;

        public Form1()
        {
            InitializeComponent();
        }
        //构造关机字符串
        private string CreateStr(Operation operation, int sec = 300)
        {
            string str = "shutdown";
            switch (operation)
            {
                case Operation.Shutdown:
                    str += " /s";
                    break;
                case Operation.Reboot:
                    str += " /r";
                    break;
                case Operation.Logout:
                    str += " /l";
                    return str;
                case Operation.Cancel:
                    str += " /a";
                    return str;
            }
            str += " /t " + sec.ToString();
            return str;
        }
        //构造cmd命令
        private string CreateOrd()
        {
            string order = "";

            if (rbtnShutdown.Checked)
            {
                order = CreateStr(Operation.Shutdown, countDown);
            }
            else if (rbtnReboot.Checked)
            {
                order = CreateStr(Operation.Reboot, countDown);
            }
            else
            {
                order = CreateStr(Operation.Logout, countDown);
            }

            return order;
        }

        private void btnExecute_Click(object sender, EventArgs e)
        {
            countDown = int.Parse(nudCount.Text);
            string order = CreateOrd();

            RunCMDCommand(order, out error);
            if (!string.IsNullOrEmpty(error))
            {
                MessageBox.Show(error);
                return;
            }
            isCount = true;
            timer1.Start();
            ControlBox = false;
            btnExecute.Enabled = false;
            btnCancel.Enabled = true;
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            string order = CreateStr(Operation.Cancel);
            RunCMDCommand(order, out error);
            if (!string.IsNullOrEmpty(error))
            {
                MessageBox.Show(error);
                return;
            }
            isCount = false;
            ControlBox = true;
            btnExecute.Enabled = true;
            btnCancel.Enabled = false;
        }

        private static string CMDPath = Environment.GetFolderPath(Environment.SpecialFolder.System) + "\\cmd.exe";

        public static void RunCMDCommand(string Command, out string Error, bool OnlyOutPutTesult = false)
        {
            using (Process pc = new Process())
            {
                Command = Command.Trim().TrimEnd('&') + "&exit";

                pc.StartInfo.FileName = CMDPath;//用户系统可能不在C盘,系统在C可以直接写cmd.exe
                //pc.StartInfo.FileName = "cmd.exe";
                pc.StartInfo.CreateNoWindow = true;//隐藏窗口运行
                pc.StartInfo.RedirectStandardError = true;//重定向错误流
                pc.StartInfo.RedirectStandardInput = true;//重定向输入流
                pc.StartInfo.RedirectStandardOutput = true;//重定向输出流
                pc.StartInfo.UseShellExecute = false;

                pc.Start();

                pc.StandardInput.WriteLine(Command);//输入CMD命令
                pc.StandardInput.AutoFlush = true;
                Error = "";
                Error = pc.StandardError.ReadToEnd();//读取结果

                if (OnlyOutPutTesult)
                {
                    int P = Error.IndexOf(Command) + Command.Length + 4;
                    Error = Error.Substring(P, Error.Length - P - 3);
                }

                pc.WaitForExit();
                pc.Close();
            }
        }
        //控制状态栏显示
        private void timer1_Tick(object sender, EventArgs e)
        {
            if (isCount)
            {
                toolStripStatusLabel1.Text = "剩余时间:" + countDown--;
            }
            else
            {
                timer1.Stop();
                toolStripStatusLabel1.Text = "等待操作...";
            }
        }
        //将秒转为年月日等
        private void nudCount_ValueChanged(object sender, EventArgs e)
        {
            int sec = (int)nudCount.Value;
            if (sec < 60)
                label2.Text = "(" + sec.ToString() + "秒)";
            else if (sec < 60 * 60)
                label2.Text = "(" + sec / 60 + "分钟" + sec % 60 + "秒)";
            else if (sec < 60 * 60 * 24)
                label2.Text = "(" + sec / (60 * 60) + "小时" + sec % (60 * 60) / 60 + "分钟)";
            else if (sec < 60 * 60 * 24 * 30)
                label2.Text = "(" + sec / (24 * 60 * 60) + "天" + sec % (24 * 60 * 60) / (60 * 60) + "小时)";
            else if (sec < 60 * 60 * 24 * 30 * 12)
                label2.Text = "(" + sec / (30 * 24 * 60 * 60) + "个月" + sec % (30 * 24 * 60 * 60) / (24 * 60 * 60) + "天)";
            else
                label2.Text = "(" + sec / (12 * 30 * 24 * 60 * 60) + "年";
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            nudCount.Value = 300;
        }

        private void rbtnLogout_CheckedChanged(object sender, EventArgs e)
        {
            if (rbtnLogout.Checked)
            {
                MessageBox.Show("注销将不能使用倒计时功能!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
        }
    }
}

免费评分

参与人数 12吾爱币 +17 热心值 +11 收起 理由
zhengchen6718 + 1 + 1 热心回复!
浮华777 + 1 + 1 我很赞同!
白帽子 + 1 + 1 谢谢@Thanks!
wuliao090 + 1 + 1 我很赞同!
yyb0919 + 1 + 1 我很赞同!
weiweilili + 1 我很赞同!
jnez112358 + 1 + 1 谢谢@Thanks!
nokia555 + 1 + 1 我很赞同!
fyypll + 1 + 1 谢谢@Thanks!
编程-修宇 + 1 + 1 感谢发布原创作品,吾爱破解论坛因你更精彩!
云在天 + 6 + 1 感谢发布原创作品,吾爱破解论坛因你更精彩!
hdh1750 + 1 + 1 谢谢@Thanks!

查看全部评分

发帖前要善用论坛搜索功能,那里可能会有你要找的答案或者已经有人发布过相同内容了,请勿重复发帖。

zzt12 发表于 2019-2-3 14:38
完全可以win+R输入“shutdown -s -t 3600”
wyangdh 发表于 2019-2-3 14:24
q01081122 发表于 2019-2-3 14:46 来自手机
谢谢分享,我用的是记事本,输入“shutdown -s -t1800”也是论坛发现的蛮方便。
fxy1208 发表于 2019-2-3 14:58
谢谢楼主分享
markfinad 发表于 2019-2-3 15:16
感谢分享,虽然用不上
siqintu 发表于 2019-2-3 15:25
q01081122 发表于 2019-2-3 14:46
谢谢分享,我用的是记事本,输入“shutdown -s -t1800”也是论坛发现的蛮方便。

做成软件更方便,但是用处不大
bachelor66 发表于 2019-2-3 15:30
直接批处理文件也可以啊                              
sd5014897 发表于 2019-2-3 15:34
不错不错 一直想要个这样的东西
大馒头123 发表于 2019-2-3 16:47
这个有点意思哦 支持原创作品
您需要登录后才可以回帖 登录 | 注册[Register]

本版积分规则 提醒:禁止复制他人回复等『恶意灌水』行为,违者重罚!

快速回复 收藏帖子 返回列表 搜索

RSS订阅|小黑屋|处罚记录|联系我们|吾爱破解 - LCG - LSG ( 京ICP备16042023号 | 京公网安备 11010502030087号 )

GMT+8, 2024-4-21 00:22

Powered by Discuz!

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表