procedure EnableDebugPriv;
const SE_DEBUG_NAME = 'SeDebugPrivilege';
var hToken: THandle;
lpLuid: TLargeInteger;
tkp: TOKEN_PRIVILEGES;
bRes: Boolean;
retlen: DWORD;
szLog: string;
begin
//*以调整和查询的方式,打开本进程的令牌环*/
bRes := OpenProcessToken( GetCurrentProcess(),
TOKEN_ADJUST_PRIVILEGES or TOKEN_QUERY,
hToken );
if (bRes) then
begin
bRes := LookupPrivilegeValue(nil, SE_DEBUG_NAME, lpLuid);
if(not bRes) then
begin
CloseHandle(hToken);
end else
begin
tkp.PrivilegeCount := 1;
tkp.Privileges[0].Luid := lpLuid;
tkp.Privileges[0].Attributes := SE_PRIVILEGE_ENABLED;
bRes := AdjustTokenPrivileges( hToken,
false,
tkp,
sizeof(TOKEN_PRIVILEGES),
nil,
retlen );
if bRes then
begin
szLog := 'IS ok';
end else
begin
szLog := 'IS FAIL';
end;
end;
end;
end;
const SE_DEBUG_NAME = 'SeDebugPrivilege';
var hToken: THandle;
lpLuid: TLargeInteger;
tkp: TOKEN_PRIVILEGES;
bRes: Boolean;
retlen: DWORD;
szLog: string;
begin
//*以调整和查询的方式,打开本进程的令牌环*/
bRes := OpenProcessToken( GetCurrentProcess(),
TOKEN_ADJUST_PRIVILEGES or TOKEN_QUERY,
hToken );
if (bRes) then
begin
bRes := LookupPrivilegeValue(nil, SE_DEBUG_NAME, lpLuid);
if(not bRes) then
begin
CloseHandle(hToken);
end else
begin
tkp.PrivilegeCount := 1;
tkp.Privileges[0].Luid := lpLuid;
tkp.Privileges[0].Attributes := SE_PRIVILEGE_ENABLED;
bRes := AdjustTokenPrivileges( hToken,
false,
tkp,
sizeof(TOKEN_PRIVILEGES),
nil,
retlen );
if bRes then
begin
szLog := 'IS ok';
end else
begin
szLog := 'IS FAIL';
end;
end;
end;
end;