windows - C# Check if Current Logged on user is Admin (Remote Machine) -


I know there are many discussions about this subject but no one really answers my exact question. I am looking for a method that checks from a distance if the user has administrator rights on logging on whether a "administrator" group or a "administrator" within a nested group member, such as "Domain Administrator" is a member of the local made for example.

Method # 1 (Work remotely but checks only the local "Admin" group):

  private bool is admin () {ArrayList mem2 = new Arrestist (); String hostName = defaultfommedal. Logged user name; // a username meets another class ({DirectoryEntry machine = New DirectoryEntry ( "WinNT: //" + mycomputer.myComputerName)) // remote computer that I get from any other category {// local administrators group Using the (DirectoryEntry Group = Machine. Find Children ("Admin", "Groups")) // Local Administrator Groups All members of group = members get the group. Invoke ("member", blank); Foreach (Object member member (IEnumerable)) {// account name string accountName = new directoryInterity (member) .name; Mem2.Add (new directory intent (member) .name); }}}} Hold (ex before) {// hold} if (mem2.Contains (hostName.ToUpper ()) || mem2.Contains (hostName.ToLower ())) return true; Second false return; }   

Method # 2 (Check both local and domain administrator privileges, but do not work remotely)

  Stable button admin () { WindowsIdentity User = new WindowsIdentity @ "user01"); Windows Principal Prince = new WindowsPinal (user); Return prin.IsInRole (WindowsBuiltInRole.Administrator); }   

So I said, I could not find any way that would answer both requirements.

  1. Check if the user is actually of administrative rights
  2. Do this remotely

    Thanks for the help!

    OK, I think I have found a way to do this, I want to use it. I played with some methods and found that the following (working)

      static bool admin (string username, string Mridinamnam) {(principal Kantaksteks ctxMacine = new PrincipalContext (ContextType.Machine) , Machinename)) {(principal contact ctxDomain = new PrincipalContext (ContextType.Domain)) {UserPrincipal up = UserPrincipal.FindByIdentity (ctxDomain, IdentityType.SamAccountName, username); Group PinyPinal GP = Group Pynishnal. FidbiIndentity (CTX Messenger, "Administrator"); Foreach (GPPGetMembers (true)) in Ugrpinnl usr {if (up! = Null) {if (up.SamAccountName.ToUpper () == usr.SamAccountName.ToUpper ()) {true; } } } } } return false; }    

Comments

Popular posts from this blog

java - ImportError: No module named py4j.java_gateway -

python - Receiving "KeyError" after decoding json result from url -

.net - Creating a new Queue Manager and Queue in Websphere MQ (using C#) -