最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

C#調(diào)用windows api關(guān)機(jī)(關(guān)機(jī)api)示例代碼分享

 更新時(shí)間:2014年01月06日 11:47:07   作者:  
本文主要介紹了C#調(diào)用windows api關(guān)機(jī)的示例代碼,大家參考使用吧

復(fù)制代碼 代碼如下:

using System;
using System.Runtime.InteropServices;

class shoutdown{

  [StructLayout(LayoutKind.Sequential, Pack=1)]
  internal struct TokPriv1Luid
  {
  public int Count;
  public long Luid;
  public int Attr;
  }
  [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 AdjustTokenPrivileges( IntPtr htok, bool disall,
  ref TokPriv1Luid newst, int len, IntPtr prev, IntPtr relen );
  [DllImport("user32.dll", ExactSpelling=true, SetLastError=true) ]
  internal static extern bool ExitWindowsEx( int flg, int rea );
  internal const int SE_PRIVILEGE_ENABLED = 0x00000002;
  internal const int TOKEN_QUERY = 0x00000008;
  internal const int TOKEN_ADJUST_PRIVILEGES = 0x00000020;
  internal const string SE_SHUTDOWN_NAME = "SeShutdownPrivilege";
  internal const int EWX_LOGOFF = 0x00000000;
  internal const int EWX_SHUTDOWN = 0x00000001;
  internal const int EWX_REBOOT = 0x00000002;
  internal const int EWX_FORCE = 0x00000004;
  internal const int EWX_POWEROFF = 0x00000008;
  internal const int EWX_FORCEIFHUNG = 0x00000010;

  private static void DoExitWin(int flg)
  {
  bool ok;
  TokPriv1Luid tp;
  IntPtr hproc = GetCurrentProcess();
  IntPtr htok = IntPtr.Zero;
  ok = OpenProcessToken( hproc, TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, ref htok );
  tp.Count = 1;
  tp.Luid = 0;
  tp.Attr = SE_PRIVILEGE_ENABLED;
  ok = LookupPrivilegeValue( null, SE_SHUTDOWN_NAME, ref tp.Luid );
  ok = AdjustTokenPrivileges( htok, false, ref tp, 0, IntPtr.Zero, IntPtr.Zero );
  ok = ExitWindowsEx( flg, 0 );
  }
  public static void Main()
  {
  Console.WriteLine("正在關(guān)閉計(jì)算機(jī)……");
  // 修改 EWX_SHUTDOWN 或者 EWX_LOGOFF, EWX_REBOOT等實(shí)現(xiàn)不同得功能。
  // 在XP下可以看到幫助信息,以得到不同得參數(shù)
  // SHUTDOWN /?
  DoExitWin(EWX_SHUTDOWN);
  }
}

相關(guān)文章

最新評論

郴州市| 柞水县| 墨竹工卡县| 房山区| 荥经县| 电白县| 东丰县| 乃东县| 隆回县| 日土县| 丹凤县| 霍城县| 铁岭县| 邳州市| 高青县| 凌云县| 吐鲁番市| 布尔津县| 合肥市| 曲水县| 阳春市| 武功县| 隆化县| 德惠市| 永清县| 高尔夫| 区。| 基隆市| 鹤岗市| 东辽县| 特克斯县| 东乡族自治县| 阳山县| 昌吉市| 桓台县| 藁城市| 成武县| 青海省| 庆阳市| 铁岭市| 海丰县|