Closed dkrutsko closed 7 years ago
Where do you want this?
Linux and Mac: http://www.linuxquestions.org/questions/programming-9/c-codes-to-check-whether-user-is-root-or-has-admin-rights-in-linux-854996/ getuid() == 0
Windows: https://msdn.microsoft.com/en-us/library/windows/desktop/bb776463(v=vs.85).aspx IsUserAnAdmin()
Hey, thanks for contributing. I'm thinking it'll be in the Process
class, right underneath the IsSys64Bit
function as a static function named IsAdmin
.
I think IsSys64Bit doesn't really fit there, and IsAdmin doesn't either. Can these be moved to a class called Environment?
Yep, I agree, but I couldn't find a better place for it at the time. I'm thinking if we can find more of these types of functions we can move it to a class called System
or something.
Okay, to build on what @czipperz mentioned (in case we ever need it). There are three main methods of implementing this functionality on Windows. The easiest, and least robust method is simply using the IsUserAnAdmin function. The second method is a bit more robust and is described here using the CheckTokenMembership
function. This is the method used in the original PR (#41) for this feature. The last method is the most robust, but is also quite complicated, it involves using AccessCheck to determine user privileges. That method is described here.
Today I came across this cool library and one of the options there is to be able to check if the running application is running as admin. There are quite the number of uses for this so its worth implementing.