基本信息
源码名称:C# 定时关机、重启、注销 示例源码
源码大小:0.06M
文件格式:.zip
开发语言:C#
更新时间:2017-10-10
   友情提示:(无需注册或充值,赞助后即可获取资源下载链接)

     嘿,亲!知识可是无价之宝呢,但咱这精心整理的资料也耗费了不少心血呀。小小地破费一下,绝对物超所值哦!如有下载和支付问题,请联系我们QQ(微信同号):78630559

本次赞助数额为: 2 元 
   源码介绍




using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Diagnostics;

namespace ShutDown
{
    public partial class Shut : Form
    {
        public Shut()
        {
            InitializeComponent();
            this.lblCurrentTime.Text = DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss");
            this.rdoOff.Checked = true;
            
        }

        private void tmrCurrentTime_Tick(object sender, EventArgs e)
        {
            this.lblCurrentTime.Text = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
            
        }

        private void btnDetermine_Click(object sender, EventArgs e)
        {
            if(DateTime.Now.ToString("yyyy-MM-dd HH:mm").CompareTo(dtpDownTime.Value.ToString("yyyy-MM-dd HH:mm"))>0)
            {
                MessageBox.Show("关机时间小于当前时间");
                return;
            }
            TimeSpan timeSpan=dtpDownTime.Value-Convert.ToDateTime( DateTime.Now.ToString("yyyy-MM-dd HH:mm"));

            int HH = Convert.ToInt32(timeSpan.TotalMinutes % 60) < 30 ? Convert.ToInt32(timeSpan.TotalHours) : Convert.ToInt32(timeSpan.TotalHours) - 1;
            DialogResult result = MessageBox.Show(HH   "小时"   Convert.ToInt32(timeSpan.TotalMinutes % 60)   "分后关机?", "询问提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Question);
            if (result == DialogResult.Cancel)
            {
                
                return;
            }
            //var myProcess = new Process();
            //myProcess.StartInfo.FileName = "cmd.exe";
            //myProcess.StartInfo.UseShellExecute = false;
            //myProcess.StartInfo.RedirectStandardInput = true;
            //myProcess.StartInfo.RedirectStandardOutput = true;
            //myProcess.StartInfo.RedirectStandardError = true;
            //myProcess.StartInfo.CreateNoWindow = true;
            //myProcess.Start();
            //myProcess.StandardInput.WriteLine("shutdown -s -t "   Convert.ToInt32(timeSpan.TotalSeconds));
            if (rdoOff.Checked == true)
            {
                Process.Start("c:/windows/system32/shutdown.exe", "-s -t "   Convert.ToInt32(timeSpan.TotalSeconds));
            }
            else if (rdoRestart.Checked == true)
            {
                Process.Start("c:/windows/system32/shutdown.exe", "-r -t "   Convert.ToInt32(timeSpan.TotalSeconds));
            }
            else
            {
                Process.Start("c:/windows/system32/shutdown.exe", "-l -t "   Convert.ToInt32(timeSpan.TotalSeconds));
            }
        }

        private void lkbCancel_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            Process.Start("c:/windows/system32/shutdown.exe", "-a " );
        }

        private void button1_Click(object sender, EventArgs e)
        {
            this.Close();
        }

      
    }
}