isPrivilegedUser property
bool
get
isPrivilegedUser
Returns true if the current process is running with elevated privileges e.g. Is running as an Administrator.
Implementation
bool get isPrivilegedUser {
var isElevated = false;
withMemory<void, Uint32>(sizeOf<Uint32>(), (phToken) {
withMemory<void, Uint32>(sizeOf<Uint32>(), (pReturnedSize) {
withMemory<void, _TokenElevation>(sizeOf<_TokenElevation>(),
(pElevation) {
if (OpenProcessToken(
GetCurrentProcess(),
TOKEN_ACCESS_MASK.TOKEN_QUERY,
phToken.cast(),
) ==
1) {
if (GetTokenInformation(
phToken.value,
TOKEN_INFORMATION_CLASS.TokenElevation,
pElevation,
sizeOf<_TokenElevation>(),
pReturnedSize,
) ==
1) {
isElevated = pElevation.ref.tokenIsElevated != 0;
}
}
if (phToken.value != 0) {
CloseHandle(phToken.value);
}
});
});
});
return isElevated;
}