01
<PRE class=brush:csharp;collapse:true;> //實現關機,重啟,注銷
02
[StructLayout(LayoutKind.Sequential, Pack = 1)]
03
internal struct TokPriv1Luid
04
{
05
public int Count;
06
public long Luid;
07
public int Attr;
08
}
09
10
//[DllImport]允許.NET調用任意非托管的C/C++基類庫,包括操作系統中的API.但與基於COM的軟件通信時,[DLLImport]不能使用.
11
[DllImport("kernel32.dll", ExactSpelling = true)]
12
internal static extern IntPtr GetCurrentProcess();
13
14
[DllImport("advapi32.dll", ExactSpelling = true, SetLastError = true)]
15
internal static extern bool OpenProcessToken(IntPtr h, int acc, ref IntPtr phtok);
16
17
[DllImport("advapi32.dll", SetLastError = true)]
18
internal static extern bool LookupPrivilegeValue(string host, string name, ref long pluid);