本帖最后由 24K霸气杰 于 2018-12-24 16:53 编辑
更新 原来可以这么简单就实现
移除了 生成cmd命令
美滋滋
https://www.lanzouj.com/i2or4bi
新代码[C#] 纯文本查看 复制代码 private void Button_Click(object sender, RoutedEventArgs e) {
int a=int.Parse(sj.Text)*60;
string xx = a.ToString();
System.Diagnostics.Process.Start("shutdown.exe", "-s -t "+xx + " -f");
}
private void Button_Click_1(object sender, RoutedEventArgs e)
{
System.Diagnostics.Process.Start("shutdown.exe", "-a");
}
自己刚刚学习了c#,由于下载软件完成以后想让他自动关机于是百度了一下自己弄出这么一个破烂东西。附送源码。
https://www.lanzouj.com/i2ogeta
写这个东西的思路是这样的。把cmd的关机代码写入到文件里 然后运行。
[C#] 纯文本查看 复制代码 private void Button_Click(object sender, RoutedEventArgs e)
{
StreamWriter sw = new StreamWriter("1.cmd");
int jutie = int.Parse(sj.Text);
int zhon = jutie * 60;
string da = Convert.ToString(zhon);
string w = "shutdown -s -t "+da+ " -f";
sw.Write(w);
sw.Close();
System.Diagnostics.Process.Start("1.cmd");
}
private void Button_Click_1(object sender, RoutedEventArgs e)
{
StreamWriter sw = new StreamWriter("2.cmd");
string w = "shutdown -a";
sw.Write(w);
sw.Close();
System.Diagnostics.Process.Start("2.cmd");
} |