|  | 
 
| 我用 DELPHI 在2003下写的程序应用下面代码,在XP和2003下已经可以实现重启和关闭电脑, 但是在PE下执行却失效了,没有反映,也没有报错 ,不知何故?是否精简文件的问题?
 
 提升操作权限的函数:
 procedure AdjustToken();
 var
 hdlProcessHandle: Cardinal;
 hdlTokenHandle: Cardinal;
 tmpLuid: Int64;
 //tkpPrivilegeCount: Int64;
 tkp: TOKEN_PRIVILEGES;
 tkpNewButIgnored: TOKEN_PRIVILEGES;
 lBufferNeeded: Cardinal;
 Privilege: array[0..0] of _LUID_AND_ATTRIBUTES;
 begin
 hdlProcessHandle := GetCurrentProcess;
 OpenProcessToken(hdlProcessHandle,
 (TOKEN_ADJUST_PRIVILEGES or TOKEN_QUERY),
 hdlTokenHandle);
 // Get the LUID for shutdown privilege.
 LookupPrivilegeValue('', 'SeShutdownPrivilege', tmpLuid);
 Privilege[0].Luid := tmpLuid;
 Privilege[0].Attributes := SE_PRIVILEGE_ENABLED;
 tkp.PrivilegeCount := 1; // One privilege to set
 tkp.Privileges[0] := Privilege[0];
 // Enable the shutdown privilege in the access token of this
 // process.
 AdjustTokenPrivileges(hdlTokenHandle,
 False,
 tkp,
 Sizeof(tkpNewButIgnored),
 tkpNewButIgnored,
 lBufferNeeded);
 end;
 
 
 关机代码:
 AdjustToken;
 ExitWindowsEx(EWX_SHUTDOWN or EWX_FORCE,0);
 
 重启代码:
 AdjustToken;
 ExitWindowsEx(EWX_REBOOT OR EWX_FORCE,0);
 | 
 |