用C#执行命令行的命令,执行开机启动

来源:互联网 发布:三国杀武将淘宝买 编辑:程序博客网 时间:2024/06/14 13:01
 public void Init()
        {
            #region 如果是礼拜六,或者礼拜天,就自动关机,并且把指定的应用程序关闭
            DateTime datetime_now = DateTime.Now;
            if (datetime_now.DayOfWeek == DayOfWeek.Friday || datetime_now.DayOfWeek == DayOfWeek.Saturday || datetime_now.DayOfWeek == DayOfWeek.Sunday)
            {
                //如果周六,或者周日  9点之前 就关机
                if (datetime_now.Hour < 9)
                {  
                    //关机程序
                    ProcessStartInfo processStartInfo = new ProcessStartInfo("cmd.exe");
                    processStartInfo.UseShellExecute = false;
                    processStartInfo.RedirectStandardInput = true;
                    processStartInfo.RedirectStandardOutput = true;
                    processStartInfo.RedirectStandardError = true;
                    processStartInfo.CreateNoWindow = true;


                    Process process = new Process();
                    process.StartInfo = processStartInfo;
                    process.Start();
                    process.StandardInput.WriteLine("shutdown -s -t 60");
                }
            }
            #endregion


            #region 开机启动程序
            string vs2010 = @"C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\devenv.exe";
            My_RegistryKey.StartApp("VS2010", vs2010);
            string firefox_brower = @"E:\software\firefox\firefox.exe";
            My_RegistryKey.StartApp("FireFoxBrowser", firefox_brower);
            string google_brower = @"C:\Program Files (x86)\Google\Chrome\Application\chrome.exe";
            My_RegistryKey.StartApp("GoogleBrowser", google_brower);
            string rtx = @"C:\Program Files (x86)\Tencent\RTXC\RTX.exe";
            My_RegistryKey.StartApp("RTX", rtx);
            #endregion
             
            
        }
    }
0 0