01
<PRE
class
=brush:csharp;collapse:
true
;>
// Implement shutdown, restart, and logout
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] allow.. NET calls any unmanaged C/C ++ base class libraries, including the APIs in the operating system. however, [DLLImport] cannot be used for communication with COM-based software.
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);