문제

Extending this question: Detect if running as Administrator with or without elevated privileges?

The most voted answer works if the account to "run as administrator" is a local administrator but if you use a domain administrator account the variable isProcessAdmin returns false. In contrast, UAC accepts the Domain Administrator as a valid account when elevating privileges (create folder in c:\windows\, run as administrator, etc)...How can i modify the UACHelper.IsProcessElevated so it takes into account that case too?

도움이 되었습니까?

해결책

You need to pass the domain values to IsInRole:

// DOMAINNAME\Domain Admins RID: 0x200
bool isElevated = principal.IsInRole(WindowsBuiltInRole.Administrator)
               || principal.IsInRole(0x200);
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top