#Region " InitiateSystemShutdownEX and related API Info "
' OpenProcessToken Constants
Private Const TOKEN_ADJUST_PRIVILEGES As Short = &H20S
Private Const TOKEN_QUERY As Short = &H8S
' LookupPrivilegeValue Constants
Private Const SE_SHUTDOWN_NAME As String = "SeShutdownPrivilege"
Private Const SE_PRIVILEGE_ENABLED As Short = &H2S
' LookupPrivilegeValue Structures
Private Structure LUID
Dim UsedPart As Integer
Dim IgnoredForNowHigh32BitPart As Integer
End Structure
' AdjustTokenPrivileges Structures
Private Structure TOKEN_PRIVILEGES
Dim PrivilegeCount As Integer
Dim pLuid As LUID
Dim Attributes As Integer
End Structure
' InitiateSystemShutdownEx Constants
Private Const SHTDN_REASON_MAJOR_OPERATINGSYSTEM As Integer = &H20000
Private Const SHTDN_REASON_MINOR_RECONFIG As Integer = &H4
Private Const SHTDN_REASON_FLAG_PLANNED As Integer = &H80000000
Private Declare Function InitiateSystemShutdownEx Lib "advapi32" Alias "InitiateSystemShutdownExA" _
(ByVal lpMachineName As String, _
ByVal lpMessage As String, _
ByVal dwTimeout As Integer, _
ByVal bForceAppsClosed As Boolean, _
ByVal bRebootAfterShutdown As Boolean, _
ByVal dwReason As Integer) As Integer
Private Declare Function GetCurrentProcess Lib "kernel32" () As Integer
Private Declare Function OpenProcessToken Lib "advapi32" _
(ByVal ProcessHandle As Integer, _
ByVal DesiredAccess As Integer, _
ByRef TokenHandle As Integer) As Integer
Private Declare Function LookupPrivilegeValue Lib "advapi32" Alias "LookupPrivilegeValueA" _
(ByVal lpSystemName As String, _
ByVal lpName As String, _
ByRef lpLuid As LUID) As Integer
Private Declare Function AdjustTokenPrivileges Lib "advapi32" _
(ByVal TokenHandle As Integer, _
ByVal DisableAllPrivileges As Integer, _
ByRef NewState As TOKEN_PRIVILEGES, _
ByVal BufferLength As Integer, _
ByRef PreviousState As TOKEN_PRIVILEGES, _
ByRef ReturnLength As Integer) As Integer
#End Region