我想用WINDOWS.NET实现一个定时关机的程序,然后是调用CMD来执行的,现在有一个问题就是
比如:
向CMD写入这个语句
AT 20:00 /next:2 shutdown /s可以在下个月2号的8点关机,但是假如我想在下下个月的这个时候关机而下个月这个时候不需要关机怎么写?就相当于自己指定一个日期,明年的几月几号执行什么操作怎么实现?

解决方案 »

  1.   

    那你干脆写成bat,然后调用bat执行;
    这样你就可以谁是更改了
      

  2.   

    参考一下:        // 利用 ipconfig /all 获取本机ip信息
            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;
            }
      

  3.   

    写一个执行定时关机的批处理
    然后
    System.Diagnostics.Process.Start(AppDomain.CurrentDomain.BaseDirectory + "xxx.bat");
      

  4.   

    System.Diagnostics.Process.Start(AppDomain.CurrentDomain.BaseDirectory + "xxx.bat");
      

  5.   

    使用store procedure實現即可
      

  6.   

    可以写个windows service程序,service读取配置文件,分析配置文件来执行关机程序
      

  7.   


    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關機命令進行關機即可。
      

  8.   

    if exists(select 1 from shutdown_table where shutdown_date  = convert(char(10),getDate,111))
    begin
        set @s_temp = 'AT 20:00 shutdown /s'
        exec  master..xp_cmdshell @s_temp
    end