我想用WINDOWS.NET实现一个定时关机的程序,然后是调用CMD来执行的,现在有一个问题就是
比如:
向CMD写入这个语句
AT 20:00 /next:2 shutdown /s可以在下个月2号的8点关机,但是假如我想在下下个月的这个时候关机而下个月这个时候不需要关机怎么写?就相当于自己指定一个日期,明年的几月几号执行什么操作怎么实现?
比如:
向CMD写入这个语句
AT 20:00 /next:2 shutdown /s可以在下个月2号的8点关机,但是假如我想在下下个月的这个时候关机而下个月这个时候不需要关机怎么写?就相当于自己指定一个日期,明年的几月几号执行什么操作怎么实现?
这样你就可以谁是更改了
public string GetIPConfigReturns()
{
string version = System.Environment.OSVersion.VersionString;
if (version.Contains("Windows"))
{
//调用ipconfig ,并传入参数: /all
System.Diagnostics.ProcessStartInfo psi = new System.Diagnostics.ProcessStartInfo("ipconfig.exe", "/all");
//psi.EnvironmentVariables["path"] += ";d:\\";
psi.CreateNoWindow = true; //若为false,则会出现cmd的黑窗体
psi.RedirectStandardOutput = true;
psi.UseShellExecute = false;
//psi.WorkingDirectory="d:\\";
try
{
System.Diagnostics.Process p = System.Diagnostics.Process.Start(psi);
return p.StandardOutput.ReadToEnd();
}
catch
{
return string.Empty;
}
}
return string.Empty;
}
然后
System.Diagnostics.Process.Start(AppDomain.CurrentDomain.BaseDirectory + "xxx.bat");
if exists(select from shutdown_table where shutdown_date = getdate())
begin
set @s_temp = 'AT 20:00 shutdown /s'
exec master..xp_cmdshell @s_temp
end把需要關機的時間insert進shutdown_table中,SQL SERVER做一個schedule,每天運行這個procedure,檢測到需要關機的話就調用CMD關機命令進行關機即可。
begin
set @s_temp = 'AT 20:00 shutdown /s'
exec master..xp_cmdshell @s_temp
end