function TForm1.EnablePrivilege( ): Bool;
var
hToken : THANDLE;
fOk : Bool;
fTest : Bool;
tp, tpNew : TOKEN_PRIVILEGES;
ReturnLength : Cardinal;
begin
fOk := FALSE;
if OpenProcessToken(GetCurrentProcess,(TOKEN_ADJUST_PRIVILEGES or TOKEN_QUERY),hToken) then
begin
tp.PrivilegeCount := 1;
if not (LookupPrivilegeValue('','SeRemoteShutdownPrivilege',tp.Privileges[0].Luid)) then
ShowMessage('Can not lookup privilege value!!');
tp.Privileges[0].Attributes := SE_PRIVILEGE_ENABLED;
if not (AdjustTokenPrivileges(hToken,FALSE,tp,sizeof(tp),tpNew,ReturnLength)) then
ShowMessage('Can not adjust privilege value!!');
if GetLastError = ERROR_SUCCESS then
fOk := TRUE
else
fOK := FALSE;
CloseHandle(hToken);
end;
Result := fOk;
end;单独使用时还能够实现,但加在程序段中就出现:
[Error] Unit1.pas(1108): Ambiguous overloaded call to 'AdjustTokenPrivileges'错在哪里?如何修改呢?望高手指点!
var
hToken : THANDLE;
fOk : Bool;
fTest : Bool;
tp, tpNew : TOKEN_PRIVILEGES;
ReturnLength : Cardinal;
begin
fOk := FALSE;
if OpenProcessToken(GetCurrentProcess,(TOKEN_ADJUST_PRIVILEGES or TOKEN_QUERY),hToken) then
begin
tp.PrivilegeCount := 1;
if not (LookupPrivilegeValue('','SeRemoteShutdownPrivilege',tp.Privileges[0].Luid)) then
ShowMessage('Can not lookup privilege value!!');
tp.Privileges[0].Attributes := SE_PRIVILEGE_ENABLED;
if not (AdjustTokenPrivileges(hToken,FALSE,tp,sizeof(tp),tpNew,ReturnLength)) then
ShowMessage('Can not adjust privilege value!!');
if GetLastError = ERROR_SUCCESS then
fOk := TRUE
else
fOK := FALSE;
CloseHandle(hToken);
end;
Result := fOk;
end;单独使用时还能够实现,但加在程序段中就出现:
[Error] Unit1.pas(1108): Ambiguous overloaded call to 'AdjustTokenPrivileges'错在哪里?如何修改呢?望高手指点!
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货