@@ -87,4 +87,52 @@ public struct LastInputInfo
8787 public static extern bool GetLastInputInfo ( ref LastInputInfo plii ) ;
8888
8989 #endregion
90+
91+ #region 电源相关
92+
93+ [ DllImport ( "user32.dll" , SetLastError = true ) ]
94+ public static extern bool ExitWindowsEx ( uint uFlags , uint dwReason ) ;
95+
96+ [ DllImport ( "powrprof.dll" , SetLastError = true ) ]
97+ [ return : MarshalAs ( UnmanagedType . Bool ) ]
98+ public static extern bool SetSuspendState ( bool hibernate , bool forceCritical , bool disableWakeEvent ) ;
99+
100+ [ DllImport ( "advapi32.dll" , SetLastError = true ) ]
101+ public static extern bool OpenProcessToken ( IntPtr ProcessHandle , uint DesiredAccess , out IntPtr TokenHandle ) ;
102+
103+ [ DllImport ( "advapi32.dll" , SetLastError = true , CharSet = CharSet . Auto ) ]
104+ public static extern bool LookupPrivilegeValue ( string ? lpSystemName , string lpName , out LUID lpLuid ) ;
105+
106+ [ DllImport ( "advapi32.dll" , SetLastError = true ) ]
107+ public static extern bool AdjustTokenPrivileges ( IntPtr TokenHandle , bool DisableAllPrivileges , ref TOKEN_PRIVILEGES NewState , uint BufferLength , IntPtr PreviousState , IntPtr ReturnLength ) ;
108+
109+ [ StructLayout ( LayoutKind . Sequential ) ]
110+ public struct LUID
111+ {
112+ public uint LowPart ;
113+ public int HighPart ;
114+ }
115+
116+ [ StructLayout ( LayoutKind . Sequential ) ]
117+ public struct TOKEN_PRIVILEGES
118+ {
119+ public uint PrivilegeCount ;
120+ [ MarshalAs ( UnmanagedType . ByValArray , SizeConst = 1 ) ]
121+ public LUID_AND_ATTRIBUTES [ ] Privileges ;
122+ }
123+
124+ [ StructLayout ( LayoutKind . Sequential ) ]
125+ public struct LUID_AND_ATTRIBUTES
126+ {
127+ public LUID Luid ;
128+ public uint Attributes ;
129+ }
130+
131+ public const uint EWX_SHUTDOWN = 0x00000001 ;
132+ public const uint TOKEN_QUERY = 0x0008 ;
133+ public const uint TOKEN_ADJUST_PRIVILEGES = 0x0020 ;
134+ public const string SE_SHUTDOWN_NAME = "SeShutdownPrivilege" ;
135+ public const uint SE_PRIVILEGE_ENABLED = 0x00000002 ;
136+
137+ #endregion
90138}
0 commit comments