高手帮帮忙 用 VS 编写电脑关机程序。 怎么写。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 以前一个项目里找到的using System.Diagnostics;//首先导入这个命名空间Process p = new Process();//实例化一个独立进程p.StartInfo.FileName = "cmd.exe";//进程打开的文件为Cmdp.StartInfo.UseShellExecute = false;//是否启动系统外壳选否p.StartInfo.RedirectStandardInput = true;//这是是否从StandardInput输入p.StartInfo.CreateNoWindow = true;//这里是启动程序是否显示窗体 p.Start();//启动p.StandardInput.WriteLine("shutdown -s -t 10");//运行关机命令shutdown (-s)是关机 (-t)是延迟的时间 这里用秒计算 10就是10秒后关机p.StandardInput.WriteLine("exit");//退出cmd using System.Diagnostics;//首先导入这个命名空间if(txtpwd.text =="12345678"){Process p = new Process();//实例化一个独立进程p.StartInfo.FileName = "cmd.exe";//进程打开的文件为Cmdp.StartInfo.UseShellExecute = false;//是否启动系统外壳选否p.StartInfo.RedirectStandardInput = true;//这是是否从StandardInput输入p.StartInfo.CreateNoWindow = true;//这里是启动程序是否显示窗体p.Start();//启动p.StandardInput.WriteLine("shutdown -s -t 10");//运行关机命令shutdown (-s)是关机 (-t)是延迟的时间 这里用秒计算 10就是10秒后关机p.StandardInput.WriteLine("exit");//退出cmd}else{messagebox.show("密码不正确 无法启动关机程序");} 这上面的代码有个问题,在电脑 运行 里键入 shutdown -a 关机窗口那个还是关闭了, DllImport("user32") ] public static extern long ExitWindowsEx(long uFlags, long dwReserved ) ; [ DllImport("shell32") ] long dwReserved ; const int SHUTDOWN = 1 ; long sh ; int counter , n ; public static extern long ShellAbout(long uFlags, long dwReserved ) ; private void Timer1_Timer(object sender, System.EventArgs e ) { string CurrDate=System.DateTime.Today.ToShortDateString( ) ; string CurrTime=System.DateTime.Today.ToShortTimeString( ) ; if( this.CheckBox1.Checked == true ) { if(CurrDate== SetupDate.ToString( ) && CurrTime==SetupTime.ToString( ) ) ColseComputer( ) ; } } private void ColseComputer( ) { sh = ExitWindowsEx(SHUTDOWN, dwReserved) ; } .NET中的异常有没有什么唯一的东西来标识它呢 selectindexchanged事件添加到前台 如何读取Word中的文本? adapter不能对多表查询进行UPDATE吗?? 关于超线程序的编程问题 新建项目问题 问一个C# 语法的问题 小弟JAVA的,问大家一个小问题! .....................能谈谈你做报表打印的心得和困难(不使用水晶报表的) 我一个窗体是用ShowDialog方法显示的,我怎样才能关闭这个对话框,并返回一个值? 求一个小程序~(c#)关于强制结束进程(强制结束多个正在运行or未响应的同名程序) jf是什么意思?
Process p = new Process();//实例化一个独立进程
p.StartInfo.FileName = "cmd.exe";//进程打开的文件为Cmd
p.StartInfo.UseShellExecute = false;//是否启动系统外壳选否
p.StartInfo.RedirectStandardInput = true;//这是是否从StandardInput输入
p.StartInfo.CreateNoWindow = true;//这里是启动程序是否显示窗体
p.Start();//启动
p.StandardInput.WriteLine("shutdown -s -t 10");//运行关机命令shutdown (-s)是关机 (-t)是延迟的时间 这里用秒计算 10就是10秒后关机
p.StandardInput.WriteLine("exit");//退出cmd
using System.Diagnostics;//首先导入这个命名空间
if(txtpwd.text =="12345678")
{
Process p = new Process();//实例化一个独立进程
p.StartInfo.FileName = "cmd.exe";//进程打开的文件为Cmd
p.StartInfo.UseShellExecute = false;//是否启动系统外壳选否
p.StartInfo.RedirectStandardInput = true;//这是是否从StandardInput输入
p.StartInfo.CreateNoWindow = true;//这里是启动程序是否显示窗体
p.Start();//启动
p.StandardInput.WriteLine("shutdown -s -t 10");//运行关机命令shutdown (-s)是关机 (-t)是延迟的时间 这里用秒计算 10就是10秒后关机
p.StandardInput.WriteLine("exit");//退出cmd
}
else
{
messagebox.show("密码不正确 无法启动关机程序");
}
public static extern long ExitWindowsEx(long uFlags, long dwReserved ) ;
[ DllImport("shell32") ]
long dwReserved ;
const int SHUTDOWN = 1 ;
long sh ;
int counter , n ;
public static extern long ShellAbout(long uFlags, long dwReserved ) ; private void Timer1_Timer(object sender, System.EventArgs e )
{ string CurrDate=System.DateTime.Today.ToShortDateString( ) ;
string CurrTime=System.DateTime.Today.ToShortTimeString( ) ;
if( this.CheckBox1.Checked == true )
{
if(CurrDate== SetupDate.ToString( ) && CurrTime==SetupTime.ToString( ) )
ColseComputer( ) ;
}
}
private void ColseComputer( )
{ sh = ExitWindowsEx(SHUTDOWN, dwReserved) ; }