程序写的很简陋,满足了我的要求就好啦😄😄😄
源代码地址:https://download.csdn.net/download/huyangvista/12507983
源代码地址 百度云: 链接:https://pan.baidu.com/s/1MRo654GP_GNMEjWY7LTDvw
提取码:obv1
复制这段内容后打开百度网盘手机App,操作更方便哦
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace WindowsAutoShutdown
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
[DllImport("PowrProf.dll", CharSet = CharSet.Auto, ExactSpelling = true)]
//休眠
public static extern bool SetSuspendState(bool hiberate, bool forceCritical, bool disableWakeEvent);
[DllImport("user32")]
public static extern bool ExitWindowsEx(uint uFlags, uint dwReason);
[DllImport("user32")]
public static extern void LockWorkStation();
public static bool isDebug = false;
public enum EShutdownType
{
Shutdown, ShutdownReset, ShutdownLogout, ShutdownLock, ShutdownSleep, ShutdownRest
}
private EShutdownType shutdownType = EShutdownType.ShutdownRest;
//关机
public static void Shutdown()
{
if (isDebug) {
MessageBox.Show("执行了关机");
return;
}
Process.Start("shutdown", "/s /t 0"); //