Check if another process has admin privileges in .NET

后端 未结 4 1891
迷失自我
迷失自我 2020-12-21 05:02

I\'m looking for a way to check that a remote process has administrator privileges from my (fully managed) code. It\'s safe to assume that my code will run be run with admin

相关标签:
4条回答
  • 2020-12-21 05:46

    I have created Process.Extensions.dll extension using solution offered by Anders

    https://stackoverflow.com/a/53460693/3855622

    0 讨论(0)
  • 2020-12-21 05:47

    To check if process started with user from Administrative group you should use the way described by Anders. To check integrity level on Vista or Windows 7 use GetTokenInformation with specifing TokenIntegrityLevel token class to get TOKEN_MANDATORY_LABEL struct which contains SID associated with mandatory integrity level of the token.

    0 讨论(0)
  • 2020-12-21 06:02

    OpenProcess(PROCESS_QUERY_[LIMITED_]INFORMATION)+OpenProcessToken(TOKEN_DUPLICATE) to get the token, then DuplicateTokenEx(TOKEN_QUERY,SecurityImpersonation,TokenImpersonation) to get the impersonation token, then pass that token and the SID from CreateWellKnownSid(WinBuiltinAdministratorsSid) to CheckTokenMembership.

    To be able to open (almost) every process for PROCESS_QUERY_INFORMATION access you need to be running as administrator and with debug privileges. On Vista and later you can use PROCESS_QUERY_LIMITED_INFORMATION.

    Example code available in this answer.

    0 讨论(0)
  • 2020-12-21 06:02

    You could use GetTokenInformation or IsUserAnAdmin API calls.

    0 讨论(0)
提交回复
热议问题