关机代码

来源:百度知道 编辑:UC知道 时间:2024/06/09 03:19:07
我想写一个自己用的小程序,能实现关机,语言是c#.net
50分
我想用程序 我不喜欢用shutdown 那样容易被人关掉

using Microsoft.Win32;
using System.Runtime.InteropServices;
using System.Threading;

namespace iSchoolWebBrowser
{
class EnvironmentCheckClass
{

[DllImport("user32.dll")]
static extern bool ExitWindowsEx(ExitWindows uFlags, ShutdownReason dwReason);
[DllImport("kernel32.dll", ExactSpelling = true)]
internal static extern IntPtr GetCurrentProcess();

[DllImport("advapi32.dll", ExactSpelling = true, SetLastError = true)]
internal static extern bool OpenProcessToken(IntPtr h, int acc, ref IntPtr phtok);

[DllImport("advapi32.dll", SetLastError = true)]
internal static extern bool LookupPrivilegeValue(string host, string name, ref long pluid);

[DllImport("advapi32.dll", ExactSpelling = true, SetLastError = true)]
internal static extern bool Adju