Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Users in local users and groups

Users in local users and groups

Scheduled Pinned Locked Moved C#
sysadminhelp
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    Surya Ayyagari
    wrote on last edited by
    #1

    Hi, I need to obtain the fully list of users and groups in a Server, like you see on Users & Groups, in computer management of control pannel. And the user in the particular group. Any help or idea is greatly appreciated Thanks in advance Surya :confused:

    H 1 Reply Last reply
    0
    • S Surya Ayyagari

      Hi, I need to obtain the fully list of users and groups in a Server, like you see on Users & Groups, in computer management of control pannel. And the user in the particular group. Any help or idea is greatly appreciated Thanks in advance Surya :confused:

      H Offline
      H Offline
      Hessam Jalali
      wrote on last edited by
      #2

      you can do that using WMI through System.Management namespace (you must add it as reference) you can query Win32_UserAccount and Win32_UserGroup from WMI for collecting your data maybe this is not the best solution but it's going to work :) here is the code

      public class UserManagements
      {
      public class GroupUser
      {
      const string PATTERNNAME = ".*Name=\"(?'name'.*)\".*";
      const string PATTERNDOMAIN = ".*Domain=\"(?'domain'.*)\",.*";

                  public readonly string groupName;
                  public readonly string partName;
      
                  public readonly string groupDomain;
                  public readonly string partDomain;
      
                  public GroupUser(string groupComponent, string partComponent)
                  {
                      this.groupName = Regex.Replace(groupComponent, PATTERNNAME, "${name}");
                      this.partName = Regex.Replace(partComponent, PATTERNNAME, "${name}");
      
                      this.groupDomain = Regex.Replace(groupComponent, PATTERNDOMAIN, "${domain}");
                      this.partDomain = Regex.Replace(partComponent, PATTERNDOMAIN, "${domain}");
                  }
      
              }
      
              public class UserAccount
              {
                  public readonly int AccountType;
                  public readonly string Caption;
                  public readonly string Description;
                  public readonly bool Disabled;
                  public readonly string Domain;
                  public readonly string FullName;
      
                  public readonly bool LocalAccount;
                  public readonly bool Lockout;
                  public readonly string Name;
                  public readonly bool PasswordChangeable;
                  public readonly bool PasswordExpires;
                  public readonly bool PasswordRequired;
                  public readonly string SID;
                  public readonly int SIDType;
                  public readonly string Status;
      
                  public UserAccount(ManagementObject userMO)
                  {
                      this.AccountType = Convert.ToInt32(userMO.Properties\["AccountType"\].Value);
                      this.Caption = userMO.Properties\["Caption"\].Value as string;
                      this.Description = userMO.Properties\["Description"\].Value as string;
                      this.Disabled = Convert.ToBoolean(userMO.Properties\["AccountType"\].Value);
                      this.Domai
      
      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups