欢迎来到天天文库
浏览记录
ID:38755902
大小:44.32 KB
页数:4页
时间:2019-06-18
《定时关机小程序C#源代码》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、usingSystem;usingSystem.Collections.Generic;usingSystem.ComponentModel;usingSystem.Data;usingSystem.Drawing;usingSystem.Linq;usingSystem.Text;usingSystem.Windows.Forms;usingSystem.Runtime.InteropServices;usingSystem.Diagnostics;namespaceShutDownComputer{publicpartialclassMainForm:Fo
2、rm{publicMainForm(){InitializeComponent();t.Interval=1000;t.Tick+=newEventHandler(t_Tick);t.Start();}Timert=newTimer();voidt_Tick(objectsender,EventArgse){labelNowTime.Text=DateTime.Now.ToString();}[DllImport("user32.dll",EntryPoint="ExitWindowsEx",CharSet=CharSet.Ansi)]privatestati
3、cexternintExitWindowsEx(intuFlags,intdwReserved);privatevoid注销ToolStripMenuItem_Click(objectsender,EventArgse){ExitWindowsEx(0,0);}//定义关机方法privatevoidShutDown(){ProcessmyProcess=newProcess();myProcess.StartInfo.FileName="cmd.exe";myProcess.StartInfo.UseShellExecute=false;myProcess.S
4、tartInfo.RedirectStandardInput=true;myProcess.StartInfo.RedirectStandardOutput=true;myProcess.StartInfo.RedirectStandardError=true;myProcess.StartInfo.CreateNoWindow=true;myProcess.Start();//启动进程myProcess.StandardInput.WriteLine("shutdown-s-t0");}//定义最小化方法privatevoidHideMainForm(){t
5、his.Hide();}//定义显示方法privatevoidShowMainForm(){this.Show();this.WindowState=FormWindowState.Normal;this.Activate();}privatevoid关机ToolStripMenuItem_Click(objectsender,EventArgse){ShutDown();//调用关机方法}privatevoid关机重启ToolStripMenuItem_Click(objectsender,EventArgse){ProcessmyProcess=newPr
6、ocess();myProcess.StartInfo.FileName="cmd.exe";myProcess.StartInfo.UseShellExecute=false;myProcess.StartInfo.RedirectStandardInput=true;myProcess.StartInfo.RedirectStandardOutput=true;myProcess.StartInfo.RedirectStandardError=true;myProcess.StartInfo.CreateNoWindow=true;myProcess.St
7、art();myProcess.StandardInput.WriteLine("shutdown-r-t0");}privatevoid退出程序ToolStripMenuItem1_Click(objectsender,EventArgse){this.Close();Application.Exit();}privatevoid重新设定ToolStripMenuItem_Click(objectsender,EventArgse){numericUpDownHour.Value=1;numericUpDownMinute.Value=1;numericUp
8、DownSecond.Value=30
此文档下载收益归作者所有