ExitWindowsEx_() doesn't reboot
Posted: Mon Aug 14, 2006 8:49 pm
I'm currently working on a tool wich makes a couple of changes to the system and should ask the user to reboot in order for changes to take effect. So far, so good. I'm trying to achieve this by using the ExitWindowsEx_() API function. Doesn't work, no matter what kind of flag combinations you set. So I browsed the web and found the following article:
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:
Well, if you run that code just nothing will happen. No clue what's wrong here.
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)