Check if the other process has administrator rights in .NET.

I am looking for a way to verify that a remote process has administrator rights from my (fully managed) code. It is safe to assume that my code will be run with administrator privileges, so I do not care how invasive the method is to achieve my goal, however I am looking for a fully managed way that should be compatible with XP SP3 x86 all the way down to win7 x64.

Thanks in advance!

Edit : to clarify, I'm talking about a process running on the same computer, regardless of the user who launched it. I want to make sure that either the identifier associated with the process belongs to the Administrators group, or that the main thread has full rights, with special respect for the inheritance of descriptors opened by elevated processes, and writing to the storage without any restrictions, except for those which apply to processes generated by the option "Run as administrator".

+3
source share
3 answers

OpenProcess (PROCESS_QUERY_INFORMATION) + OpenProcessToken (TOKEN_QUERY), , SID CreateWellKnownSid (WinBuiltinAdministratorsSid) CheckTokenMembership()

() PROCESS_QUERY_INFORMATION, .

+4

To check if the process is started with a user from the administration group, you should use the method described by Anders. To check the integrity level in Vista or Windows 7, use GetTokenInformation with the token class TokenIntegrityLevelto obtain a structure TOKEN_MANDATORY_LABELthat contains the SID associated with the token integrity level.

0
source

Source: https://habr.com/ru/post/1785504/


All Articles