#TOKEN_ADJUST_PRIVILEGES = $20
#TOKEN_QUERY = $8
#EWX_POWEROFF = $8
Structure NEW_LUID_AND_ATTRIBUTES
pLuid.LUID
Attributes.l
EndStructure
Structure NEW_TOKEN_PRIVILEGES
PrivilegeCount.l
Privileges.NEW_LUID_AND_ATTRIBUTES[#ANYSIZE_ARRAY]
EndStructure
Procedure.b DitchWindows (flags)
DefType.OSVERSIONINFO
os\dwOSVersionInfoSize = SizeOf (OSVERSIONINFO)
GetVersionEx_ (os)
If os\dwPlatformId = #VER_PLATFORM_WIN32_NT
If OpenProcessToken_ (GetCurrentProcess_ (), #TOKEN_ADJUST_PRIVILEGES | #TOKEN_QUERY, @token)
If LookupPrivilegeValue_ (#Null, "SeShutdownPrivilege", tkp.NEW_TOKEN_PRIVILEGES\Privileges[0]\pLuid)
tkp\PrivilegeCount = 1
tkp\Privileges[0]\Attributes = #SE_PRIVILEGE_ENABLED
If AdjustTokenPrivileges_ (token, #False, tkp, #Null, #Null, #Null)
If ExitWindowsEx_ (flags, 0) = 0
ProcedureReturn 4
EndIf
Else
ProcedureReturn 3
EndIf
Else
ProcedureReturn 2
EndIf
Else
ProcedureReturn 1
EndIf
Else
If ExitWindowsEx_ (flags, 0) = 0
ProcedureReturn 4
EndIf
EndIf
EndProcedure
Procedure.b System_LogOff (force)
If force
force = #EWX_FORCE
EndIf
flags = #EWX_LOGOFF | force
;DitchWindows (flags)
EndProcedure
Procedure.b System_ShutDown (force)
If force
force = #EWX_FORCE
EndIf
flags = #EWX_SHUTDOWN | force
;DitchWindows (flags)
EndProcedure
Procedure.b System_Reboot (force)
If force
force = #EWX_FORCE
EndIf
flags = #EWX_REBOOT | force
;DitchWindows (flags)
EndProcedure
Procedure.b System_PowerOff (force)
If force
force = #EWX_FORCE
EndIf
flags = #EWX_POWEROFF | force
;DitchWindows (flags)
EndProcedure