分享离线下载后能够自动关机程序及程序分析
我想大家都用迅雷下载过文件,但是要是要下载的文件太大,需要的时间就会很长,我们没那么多的时间等在电脑面前,为此迅雷弄咯个迅雷离线下载来赚钱!当然你可以花钱办理迅雷会员,就可以不用长时间开机下载咯!我写的这个小程序是针对于那些普通用户。当然迅雷现在也已经添加咯下载完成自动关机的功能,但是你毕竟只有用迅雷才能用它的功能,有一定的局限性。我也是好奇,所以试着写咯个!

下面是程序的源代码(C#版的,用Java GUI写原理也一样):
这是程序的界面
代码如下:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace timeclose
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
public System.Windows.Forms.DialogResult msg = new DialogResult();
private void panel1_Paint(object sender, PaintEventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
if (DateTime.Now.Hour == int.Parse(comboBox1.Text) && DateTime.Now.Minute == numericUpDown2.Value)
{
msg = MessageBox.Show("您现在就要关机吗?建议先设置具体关机时间!", "温馨提示!", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation);
if ( msg== DialogResult.Yes)
{
System.Diagnostics.Process.Start("cmd.exe", "/c shutdown.exe -s -f");
button1.Enabled = false;
button2.Enabled = true;
}
else
return;
}
if (DateTime.Now.Hour > int.Parse(comboBox1.Text)||((DateTime.Now.Hour>=int.Parse(comboBox1.Text))&&(DateTime.Now.Minute>numericUpDown2.Value)))
{
System.Diagnostics.Process.Start("cmd.exe", "/c at " + comboBox1.SelectedItem.ToString() + ":" + numericUpDown2.Value.ToString() + " shutdown.exe -s -f");
label5.Text = "系统将在次日" + comboBox1.Text + ":" + numericUpDown2.Value.ToString() + "自动关机!";
button1.Enabled = false;
comboBox1.Enabled = false;
numericUpDown2.Enabled = false;
button2.Enabled = true;
}
else
{
label5.Text = "系统将在" + comboBox1.Text + ":" + numericUpDown2.Value.ToString() + "自动关机!";
System.Diagnostics.Process.Start("cmd.exe", "/c at " + comboBox1.SelectedItem.ToString() + ":" + numericUpDown2.Value.ToString() + " shutdown.exe -s -f");
button1.Enabled = false;
comboBox1.Enabled = false;
numericUpDown2.Enabled = false;
button2.Enabled = true;
}
}
private void button2_Click(object sender, EventArgs e)
{
if (msg == DialogResult.Yes)
{
System.Diagnostics.Process.Start("cmd.exe", "/c shutdown.exe -a");
comboBox1.Text = DateTime.Now.Hour.ToString();
numericUpDown2.Value = DateTime.Now.Minute;
label5.Text = "定时关机已取消!";
button1.Enabled = true;
comboBox1.Enabled = true;
numericUpDown2.Enabled = true;
comboBox1.Focus();
button2.Enabled = false;
}
else
{
System.Diagnostics.Process.Start("cmd.exe", "/c at " + comboBox1.SelectedItem.ToString() + ":" + numericUpDown2.Value.ToString() + " shutdown.exe -a");
comboBox1.Text = DateTime.Now.Hour.ToString();
numericUpDown2.Value = DateTime.Now.Minute;
label5.Text = "定时关机已取消!";
button1.Enabled = true;
comboBox1.Enabled = true;
numericUpDown2.Enabled = true;
comboBox1.Focus();
button2.Enabled = false;
}
}
private void button3_Click(object sender, EventArgs e)
{
this.Close();
}
private void timer1_Tick(object sender, EventArgs e)
{
label1.Text =DateTime.Now.ToString()+" "+DateTime.Now.DayOfWeek.ToString();
timer1.Interval = 1000;
}
private void Form1_Load(object sender, EventArgs e)
{
comboBox1.Text = DateTime.Now.Hour.ToString();
numericUpDown2.Value = DateTime.Now.Minute;
comboBox1.Focus();
}
}
}
我写这个小程序的初衷也是方便自己定时关机,其实xp的System32文件夹下已经包含咯关机的程序shutdown.exe,要实现定时关机就要在命令行里敲命令,带上相应的参数也可以实现,但是命令不好记,敲起来不方便!把它界面化是我的最终目的。
程序写好后,把项目编译后的.exe文件添加快捷方式到桌面就OK咯。
本文来源 我爱IT技术网 http://www.52ij.com/jishu/118.html 转载请保留链接。
- 评论列表(网友评论仅供网友表达个人看法,并不表明本站同意其观点或证实其描述)
-
