本篇实例演示C#winform电脑关机
创建winform添加一个按钮
Cs文件代码
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 CloseDemo
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
#region 方法 电脑关机
[StructLayout(LayoutKind.Sequential, Pack = 1)]
internal struct TokPriv1Luid
{
public int Count;
public long Luid;
public int Attr;
}
[DllImport("kernel32.dll", ExactSpelling &#