C#写的自动关机及执行CMD命令
来源:互联网 发布:四川网络广播电视台app 编辑:程序博客网 时间:2024/06/05 18:14
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Diagnostics;
namespace WindowsApplication1
...{
public partial class Form1 : Form
...{
int i = 0;
private int ti;
public Form1()
...{
InitializeComponent();
timer1.Enabled = false;
}
public string CmdPc(string cmdinput)
...{
Process p = new Process();
p.StartInfo.FileName = "cmd.exe";
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardInput = true;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.CreateNoWindow = true;
try
...{
p.Start();
p.StandardInput.WriteLine(cmdinput);
p.StandardInput.WriteLine("exit");
string ss=p.StandardOutput.ReadToEnd();
p.WaitForExit();
p.Close();
return ss;
}
catch
...{
string ss = "命令执行失败";
return ss;
}
}
private void button1_Click(object sender, EventArgs e)
...{
//label1.Text = ClosePc();
if (textBox2.Text != "")
...{
ti = Convert.ToInt32(textBox2.Text);
timer1.Enabled = true;
button3.Enabled = true;
button4.Enabled = true;
button1.Enabled = false;
}
else ...{ label4.Text = "请输入时间,单位/分钟"; }
}
private void timer1_Tick(object sender, EventArgs e)
...{
if (ti - i == 1)//从5开始到计时
...{
timer1.Enabled = false;
label4.Text = "时间到,关机!!";
label1.Text = CmdPc("Shutdown.exe -s -f");
button4.Visible = true;
}
else
...{
i++;
string j = (ti - i).ToString();
label4.Text = j;
}
}
private void button3_Click(object sender, EventArgs e)
...{
timer1.Enabled = true;
button4.Enabled = true;
button1.Enabled = true;
}
private void button2_Click(object sender, EventArgs e)
...{
label1.Text=CmdPc(textBox1.Text);
}
private void button4_Click_1(object sender, EventArgs e)
...{
timer1.Enabled = false;
button4.Enabled = false;
button1.Enabled = true;
label4.Text = "停止";
}
private void textBox2_KeyPress(object sender, KeyPressEventArgs e)
...{
if (e.KeyChar == 13)
...{
ti = Convert.ToInt32(textBox2.Text);
timer1.Enabled = true;
button3.Enabled = true;
button4.Enabled = true;
button1.Enabled = false;
}
}
}
}
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Diagnostics;
namespace WindowsApplication1
...{
public partial class Form1 : Form
...{
int i = 0;
private int ti;
public Form1()
...{
InitializeComponent();
timer1.Enabled = false;
}
public string CmdPc(string cmdinput)
...{
Process p = new Process();
p.StartInfo.FileName = "cmd.exe";
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardInput = true;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.CreateNoWindow = true;
try
...{
p.Start();
p.StandardInput.WriteLine(cmdinput);
p.StandardInput.WriteLine("exit");
string ss=p.StandardOutput.ReadToEnd();
p.WaitForExit();
p.Close();
return ss;
}
catch
...{
string ss = "命令执行失败";
return ss;
}
}
private void button1_Click(object sender, EventArgs e)
...{
//label1.Text = ClosePc();
if (textBox2.Text != "")
...{
ti = Convert.ToInt32(textBox2.Text);
timer1.Enabled = true;
button3.Enabled = true;
button4.Enabled = true;
button1.Enabled = false;
}
else ...{ label4.Text = "请输入时间,单位/分钟"; }
}
private void timer1_Tick(object sender, EventArgs e)
...{
if (ti - i == 1)//从5开始到计时
...{
timer1.Enabled = false;
label4.Text = "时间到,关机!!";
label1.Text = CmdPc("Shutdown.exe -s -f");
button4.Visible = true;
}
else
...{
i++;
string j = (ti - i).ToString();
label4.Text = j;
}
}
private void button3_Click(object sender, EventArgs e)
...{
timer1.Enabled = true;
button4.Enabled = true;
button1.Enabled = true;
}
private void button2_Click(object sender, EventArgs e)
...{
label1.Text=CmdPc(textBox1.Text);
}
private void button4_Click_1(object sender, EventArgs e)
...{
timer1.Enabled = false;
button4.Enabled = false;
button1.Enabled = true;
label4.Text = "停止";
}
private void textBox2_KeyPress(object sender, KeyPressEventArgs e)
...{
if (e.KeyChar == 13)
...{
ti = Convert.ToInt32(textBox2.Text);
timer1.Enabled = true;
button3.Enabled = true;
button4.Enabled = true;
button1.Enabled = false;
}
}
}
}
- C#写的自动关机及执行CMD命令
- C# 执行CMD命令
- C# 执行CMD命令
- C#执行CMD命令
- c# 执行CMD命令
- c#执行cmd命令
- c#执行windows的cmd命令操作
- C# 调用执行CMD命令
- 写能执行cmd命令的bat文件
- 通过电脑自带的cmd和Dos命令设置电脑自动关机以及取消自动关机
- XP自动关机及重启的命令
- c# 调用CMD命令执行dos命令
- C#执行DOS命令(CMD命令)
- C#执行DOS命令(CMD命令)
- C#执行DOS命令(CMD命令)
- C#执行CMD命令并返回结果
- c#中调用cmd命令执行批处理文件
- c#中调用cmd命令执行批处理文件
- 常用数据库的链接方法
- 五种提高 SQL 性能的方法
- C#反编译及混淆器
- asp.net Ajax ---AutoComplete控件使用
- 网页特效-背景特效-简单实用的下雪背景
- C#写的自动关机及执行CMD命令
- PHP使用SOAP做webservice
- 介绍一款可视化的流程定义工具
- php使用DOM处理xml文档
- 国内比较全的华硕EPC论坛
- C#重定向 进程调用 WinForm多线程
- Struts2拦截器的使用
- PHP通过SimpleXML访问xml文档
- 什么才是ajax!!!!!?????