zoukankan      html  css  js  c++  java
  • C# 定时关机代码

    c#定时关机代码

    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Runtime.InteropServices;
    using System.Text;
    using System.Threading.Tasks;
    using System.Windows.Forms;
    
    namespace PCShutDown
    {
        public partial class Form2 : Form
        {
            public Form2()
            {
                InitializeComponent();
            }
    
            private void Form2_Load(object sender, EventArgs e)
            {
                
            }
    
            string cmd = @"c:WindowsSystem32shutdown.exe";
    
            /// <summary>
            /// 锁定电脑
            /// </summary>
            [DllImport("User32.DLL")]
            public static extern void LockWorkStation();
            private void btn_Lock_Click(object sender, EventArgs e)
            {
                if (MessageBox.Show("确定要锁定电脑吗?", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK)
                {
                    LockWorkStation();
                }
            }
    
            /// <summary>
            /// 重启电脑
            /// </summary>
            /// <param name="sender"></param>
            /// <param name="e"></param>
            private void btn_Reboot_Click(object sender, EventArgs e)
            {
                if (MessageBox.Show("确定要重记电脑吗?", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK)
                {
    
                    System.Diagnostics.Process.Start("shutdown.exe", " -r -t 60");
                }
            }
            /// <summary>
            /// 关机
            /// </summary>
            /// <param name="sender"></param>
            /// <param name="e"></param>
            private void btn_Shutdown_Click(object sender, EventArgs e)
            {
                if (MessageBox.Show("确定要关机吗?", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK)
                {
                    System.Diagnostics.Process.Start("shutdown.exe", " -s -t 60");
                }
            }
    
            /// <summary>
            /// 取消操作
            /// </summary>
            /// <param name="sender"></param>
            /// <param name="e"></param>
            private void btn_Cancel_Click(object sender, EventArgs e)
            {
                if (MessageBox.Show("确定要取消吗?", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK)
                {
                    System.Diagnostics.Process.Start("shutdown.exe", " -a");
                    textBox1.AppendText("提示: 操作时间:" + DateTime.Now.ToString() + " 任务已取消" + "
    ");
                }
    
            }
    
    
            /// <summary>
            /// 休眠
            /// </summary>
            /// <param name="hiberate"></param>
            /// <param name="forceCritical"></param>
            /// <param name="disableWakeEvent"></param>
            /// <returns></returns>
    
            [DllImport("PowrProf.dll", CharSet = CharSet.Auto, ExactSpelling = true)]
            public static extern bool SetSuspendState(bool hiberate, bool forceCritical, bool disableWakeEvent);
    
            private void button2_Click(object sender, EventArgs e)
            {
                if (MessageBox.Show("确定进入睡眠模式吗?", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK)
                {
                    SetSuspendState(true, true, true);
                }
    
                showTime.Text = GetStartTime().ToString();
            }
    
    
          
    
        }
    }
    

      

  • 相关阅读:
    转dhdhtmlxTree
    转Merge的用法
    解决SqlServer2008评估期过期
    借鉴一下对比算法
    Asp.Net异常:"由于代码已经过优化或者本机框架位于调用堆栈之上,无法计算表达式的值"的解决方法
    查看Windows下引起Oracle CPU占用率高的神器-qslice
    今日有奖活动一览
    【分享】给做技术的战友们推荐一个不错的微信公号解解闷
    Unreal Engine Plugin management
    当在ECLIPSE中import现存项目时,如遇到版本不符
  • 原文地址:https://www.cnblogs.com/nymz/p/14206414.html
Copyright © 2011-2022 走看看