procedure MyShutDown;<br> procedure AdjustToken;<br> var<br> hdlProcessHandle : Cardinal;<br> hdlTokenHandle : Cardinal;<br> tmpLuid : Int64;<br> tkpPrivilegeCount : Int64;<br> tkp : TOKEN_PRIVILEGES;<br> tkpNewButIgnored : TOKEN_PRIVILEGES;<br> lBufferNeeded : Cardinal;<br> Privilege : array[0..0] of _LUID_AND_ATTRIBUTES;<br> begin<br> hdlProcessHandle := GetCurrentProcess;<br> OpenProcessToken(hdlProcessHandle,(TOKEN_ADJUST_PRIVILEGES Or TOKEN_QUERY),hdlTokenHandle);<br> // Get the LUID for shutdown privilege.<br> LookupPrivilegeValue('', 'SeShutdownPrivilege', tmpLuid);<br> Privilege[0].Luid := tmpLuid;<br> Privilege[0].Attributes := SE_PRIVILEGE_ENABLED;<br> tkp.PrivilegeCount := 1; // One privilege to set<br> tkp.Privileges[0] := Privilege[0];<br> // Enable the shutdown privilege in the access token of this<br> // process.<br> AdjustTokenPrivileges(hdlTokenHandle, False, tkp, Sizeof(tkpNewButIgnored), tkpNewButIgnored, lBufferNeeded);<br> end;<br>var<br> hProcess,hAccessToken:THandle;<br> LUID_AND_ATTRIBUTES:TLUIDAndAttributes;<br> TOKEN_PRIVILEGES: TTokenPrivileges;<br> BufferIsNull
WORD;<br>Const<br> SE_SHUTDOWN_NAME='SeShutdownPrivilege';<br>begin<br> hProcess:=GetCurrentProcess();<br> OpenProcessToken(hprocess,TOKEN_ADJUST_PRIVILEGES+TOKEN_QUERY,hAccessToken);<br> LookupPrivilegeValue(Nil,SE_SHUTDOWN_NAME,LUID_AND_ATTRIBUTES.Luid);<br> LUID_AND_ATTRIBUTES.Attributes:=SE_PRIVILEGE_ENABLED;<br> TOKEN_PRIVILEGES.PrivilegeCount:=1;<br> TOKEN_PRIVILEGES.Privileges[0]:=LUID_AND_ATTRIBUTES;<br> BufferIsNull:=0;<br> AdjustTokenPrivileges(hAccessToken,False,TOKEN_PRIVILEGES,sizeof(TOKEN_PRIVILEGES),Nil,BufferIsNull);<br> ExitWindowsEX(1, EWX_SHUTDOWN);<br>end;