SetPrivilege proc hToken:dword,lpszPrivilege:dword,bEnablePrivilege:dword
local tp:TOKEN_PRIVILEGES
local luid:LUID
invoke LookupPrivilegeValue,0,lpszPrivilege,addr luid
test eax,eax
jz @err
mov tp.PrivilegeCount,1
push luid.LowPart
pop tp.Privileges[0].Luid.LowPart
push luid.HighPart
pop tp.Privileges[0].Luid.HighPart
mov eax,bEnablePrivilege
.if eax == 1
mov tp.Privileges[0].Attributes,SE_PRIVILEGE_ENABLED
.else
xor eax,eax
mov tp.Privileges[0].Attributes,eax
.endif
invoke AdjustTokenPrivileges,hToken,FALSE,addr tp,sizeof TOKEN_PRIVILEGES,0,0
test eax,eax
jz @err
invoke GetLastError
cmp eax,ERROR_NOT_ALL_ASSIGNED
je @err
;ALL OK, return TRUE
xor eax,eax
inc eax
jmp @ex
@err:
fn MessageBox,0,LastError$(),"Last Error Text",MB_OK
xor eax,eax ;else return FALSE
@ex:
ret
SetPrivilege endp
usage
invoke SetPrivilege,hToken,chr$("SeDebugPrivilege"),TRUE