我想将我的电脑给个时间让它定时开关机该怎么写代码啊?

解决方案 »

  1.   

    使用Timer啊
    至于怎么关机,百度一下,关机的Win32 API
      

  2.   

    用系统时间与你规定的时间做比较`有时钟监视~~  当他们相同的时候 调用shutdown命令就可以了
      

  3.   

    有段遠程關閉電腦的列子,可參考一下
    ConnectionOptions options = new ConnectionOptions();
                options.Username = "diom\administrator";// textBox2.Text;
                options.Password = "123";//textBox3.Text;
                ManagementScope scope = new ManagementScope("\\\\" + IP + "\\root\\cimv2", options);
                try
                {
                    string sss=System.Environment.UserName;
                    //用给定管理者用户名和口令连接远程的计算机 
                    scope.Connect();
                    
                    ObjectQuery oq = new ObjectQuery("select * from win32_OperatingSystem");
                    ManagementObjectSearcher query1 = new ManagementObjectSearcher(scope, oq);
                    
                    ManagementObjectCollection queryCollection1 = query1.Get();
                    foreach (ManagementObject mo in queryCollection1)
                    {
                        string[] ss ={ "" };
                        string s1=mo["Caption"].ToString();
                        string s2 = mo["Manufacturer"].ToString();
                        string s3 = mo["csname"].ToString();
                        string s4 = mo["WindowsDirectory"].ToString();
                        string s5 = "";
                        mo.InvokeMethod("Reboot", ss);
                    }
                }
      

  4.   

    哦 有创意
    马云说懒人创造了世界,在支撑这个世界前进
    看来楼主是马云的fans了
      

  5.   

    定时关机(直接就写上来了,好不好使还没试呢,不好使可别骂我, 你再调一下,应该这样是行的,呵呵):
    ProcessStartInfo info = new ProcessStartInfo();
                info.FileName = "cmd.exe";
                info.WindowStyle = ProcessWindowStyle.Hidden;
                info.Arguments = "shutdown -s -t 0";
                info.WorkingDirectory = "C:\\";System.Timers.Timer bakTimer = new System.Timers.Timer(1000);
    bakTimer.Elapsed += new System.Timers.ElapsedEventHandler(bakTimer_Elapsed);private void bakTimer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
    {
          if(DataTime.Now == [你设定的关机时间])    //关机时间怎么设置,就不用我说了吧,看你喜欢的方式而定了
                Process.Start(info);
    }定时开机我也不会? 等待高手,跟着学习一下
      

  6.   

    自动开机需要硬件支持,在BIOS里使用 电源管理功能
    自动关机.... 看LS各位叙述~如果你想实现自动开机使用代码,我想可以考虑察看一下关于系统休眠或者挂起的功能.