Click here to Skip to main content
15,891,567 members
Home / Discussions / C#
   

C#

 
AnswerRe: How to log before window shutdowned! Pin
Abhijit Jana6-Oct-07 2:26
professionalAbhijit Jana6-Oct-07 2:26 
QuestionClient-Server [modified] Pin
Aamu6-Oct-07 1:05
Aamu6-Oct-07 1:05 
QuestionThreading Pin
udikantz6-Oct-07 0:46
udikantz6-Oct-07 0:46 
AnswerRe: Threading Pin
lmoelleb6-Oct-07 1:00
lmoelleb6-Oct-07 1:00 
GeneralRe: Threading Pin
udikantz6-Oct-07 1:52
udikantz6-Oct-07 1:52 
GeneralRe: Threading Pin
lmoelleb6-Oct-07 3:35
lmoelleb6-Oct-07 3:35 
GeneralRe: Threading Pin
udikantz6-Oct-07 6:16
udikantz6-Oct-07 6:16 
Questionhow to check the files are exist or not in a floder Pin
ramyanaidu5-Oct-07 22:45
ramyanaidu5-Oct-07 22:45 
AnswerRe: how to check the files are exist or not in a floder Pin
Hessam Jalali5-Oct-07 23:03
Hessam Jalali5-Oct-07 23:03 
AnswerRe: how to check the files are exist or not in a floder Pin
Abhijit Jana5-Oct-07 23:52
professionalAbhijit Jana5-Oct-07 23:52 
QuestionCancelling a background worker Pin
Muammar©5-Oct-07 22:40
Muammar©5-Oct-07 22:40 
AnswerRe: Cancelling a background worker Pin
Hessam Jalali6-Oct-07 0:19
Hessam Jalali6-Oct-07 0:19 
GeneralRe: Cancelling a background worker Pin
Muammar©6-Oct-07 0:39
Muammar©6-Oct-07 0:39 
GeneralRe: Cancelling a background worker Pin
Hessam Jalali6-Oct-07 1:00
Hessam Jalali6-Oct-07 1:00 
GeneralRe: Cancelling a background worker Pin
Muammar©6-Oct-07 1:33
Muammar©6-Oct-07 1:33 
QuestionCopying files to clipboard?? Pin
Muammar©5-Oct-07 22:19
Muammar©5-Oct-07 22:19 
AnswerRe: Copying files to clipboard?? Pin
pmarfleet5-Oct-07 22:37
pmarfleet5-Oct-07 22:37 
GeneralRe: Copying files to clipboard?? Pin
Muammar©5-Oct-07 22:53
Muammar©5-Oct-07 22:53 
GeneralRe: Copying files to clipboard?? Pin
User 66586-Oct-07 2:11
User 66586-Oct-07 2:11 
GeneralRe: Copying files to clipboard?? Pin
Muammar©6-Oct-07 11:31
Muammar©6-Oct-07 11:31 
QuestionUsers in local users and groups Pin
Surya Ayyagari5-Oct-07 22:02
Surya Ayyagari5-Oct-07 22:02 
AnswerRe: Users in local users and groups [modified] Pin
Hessam Jalali5-Oct-07 23:57
Hessam Jalali5-Oct-07 23:57 
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 Smile | :)

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.Domain = userMO.Properties["Domain"].Value as string;
                    this.FullName = userMO.Properties["FullName"].Value as string;

                    this.LocalAccount = Convert.ToBoolean(userMO.Properties["LocalAccount"].Value);
                    this.Lockout = Convert.ToBoolean(userMO.Properties["Lockout"].Value);
                    this.Name = userMO.Properties["Name"].Value as string;
                    this.PasswordChangeable = Convert.ToBoolean(userMO.Properties["PasswordChangeable"].Value);
                    this.PasswordExpires = Convert.ToBoolean(userMO.Properties["PasswordExpires"].Value);
                    this.PasswordRequired = Convert.ToBoolean(userMO.Properties["PasswordRequired"].Value);
                    this.SID = userMO.Properties["SID"].Value as string;
                    this.SIDType = Convert.ToInt32(userMO.Properties["SIDType"].Value);
                    this.Status = userMO.Properties["Status"].Value as string;
                }
            }

            public static GroupUser[] GetGroupUsers()
            {
                List <GroupUser> groupUsers = new List <GroupUser>();
                ManagementObjectSearcher mos = new ManagementObjectSearcher(new SelectQuery("Win32_GroupUser"));
                ManagementObjectCollection moc = mos.Get();
                foreach (ManagementObject mo in moc)
                {
                    string groupComponent = mo.Properties["GroupComponent"].Value as string;
                    string partComponent = mo.Properties["PartComponent"].Value as string;

                    GroupUser gu = new GroupUser(groupComponent, partComponent);
                    groupUsers.Add(gu);
                }
                return groupUsers.ToArray();
            }

            public static UserAccount[] GetUserAccounts()
            {
                List <UserAccount> userAccounts = new List <UserAccount>();
                ManagementObjectSearcher mos = new ManagementObjectSearcher(new SelectQuery("Win32_UserAccount"));
                ManagementObjectCollection moc = mos.Get();
                foreach (ManagementObject mo in moc)
                    userAccounts.Add(new UserAccount(mo));

                return userAccounts.ToArray();
            }
        }


you can use it through GetUserGroups and GetUserAccounts methods.

hope the post would be useful

Smile | :)


-- modified at 6:02 Saturday 6th October, 2007
QuestionSelecting an item in a listbox control Pin
Muammar©5-Oct-07 21:43
Muammar©5-Oct-07 21:43 
AnswerRe: Selecting an item in a listbox control Pin
Hessam Jalali5-Oct-07 23:00
Hessam Jalali5-Oct-07 23:00 
GeneralRe: Selecting an item in a listbox control Pin
Muammar©5-Oct-07 23:17
Muammar©5-Oct-07 23:17 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.