http://support.microsoft.com/default.aspx?scid=kb;en-us;176695
Seems exactly the solution to my problem so I converted the code to PB:
Code: Select all
Procedure AdjustToken()
Protected tmpLuid.LUID
Protected tkp.TOKEN_PRIVILEGES
Protected tkpNewButIgnored.TOKEN_PRIVILEGES
hdlProcessHandle = GetCurrentProcess_()
OpenProcessToken_(hdlProcessHandle,#TOKEN_ADJUST_PRIVILEGES | #TOKEN_QUERY,@hdlTokenHandle)
; Get the LUID for shutdown privilege.
LookupPrivilegeValue_("","SeShutdownPrivilege",tmpLuid)
tkp\PrivilegeCount = 1 ;' One privilege to set
tkp\Privileges\LUID\LowPart = tmpLuid
tkp\Privileges\LUID\HighPart = tmpLuid
tkp\Privileges\Attributes = #SE_PRIVILEGE_ENABLED
lBufferNeeded = AllocateMemory(200)
; Enable the shutdown privilege in the access token of this process.
AdjustTokenPrivileges_(hdlTokenHandle,#False,tkp,SizeOf(tkpNewButIgnored),tkpNewButIgnored,lBufferNeeded)
EndProcedure
AdjustToken()
ExitWindowsEx_(#EWX_SHUTDOWN | #EWX_FORCE | #EWX_REBOOT,$FFFF)
