本帖最后由 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);
}
}
}
}
|