SIGN UP MEMBER LOGIN:    
ARTICLE

Getting detailed Information about Windows User Accounts with WMI and C#

Posted by Kirtan Patel Articles | .NET Remoting in C# August 05, 2010
Article about how to get detailed information about windows users through WMI.
Reader Level:
Download Files:
 

This article is aimed about how to get detailed information about Windows user accounts like accounts SID, SID type, Name, caption, Account domain and whether Account Status is OK, degraded unknown etc through  WMI.

To access account information of windows users we need to Use System.Management  name space.

To use this namespace first of all we need to add reference to System.management by

Project Menu>>Add Reference.

after that at the top of the code use

using System.Management; so that you can use of its classes .

Now its simple to get information about any Windows user Account through querying ManagementObjectSearcher Class .

we can get all information about Windows User through Win32_Account class .

so we need to query on that class to get related Management object and then we just need to get various properties related to it .

I have setup Interface like below that contain one combo box and some labels to get information.

8-5-2010 5-15-19 PM.gif

private void Form1_Load(object sender, EventArgs e)

        {

            ManagementObjectSearcher mos = new ManagementObjectSearcher("select * from Win32_Account");

            foreach (ManagementObject mo in mos.Get())

            {

                cmbSelectUser.Items.Add(mo["Name"].ToString());

            }

 

        }

 

        private void cmbSelectUser_SelectedIndexChanged(object sender, EventArgs e)

        {

            ManagementObjectSearcher mos = new ManagementObjectSearcher("select * from Win32_Account where Name='" + cmbSelectUser.SelectedItem.ToString() + "'");

            foreach (ManagementObject mo in mos.Get())

            {

                lblCaption.Text = mo["Caption"].ToString();

                lblDescription.Text = mo["Description"].ToString();

                lblDomain.Text = mo["Domain"].ToString();

                lblLocalAccount.Text = ((bool)mo["LocalAccount"]).ToString();       

                lblName.Text = mo["Name"].ToString();

                lblSID.Text = mo["SID"].ToString();

                lblStatus.Text = mo["Status"].ToString();

                lblSIDType.Text = mo["SIDType"].ToString();

 

            }

        }

Code is simple to understand just we have query the Management Object and displayed various properties .

Thank you :)


Login to add your contents and source code to this article
share this article :
post comment
 

thank you sir :)

Posted by Kirtan Patel Aug 06, 2010

Keep it up Kirtan.

Posted by Mahesh Chand Aug 06, 2010
6 Months Free & No Setup Fees ASP.NET Hosting!
Become a Sponsor
PREMIUM SPONSORS
  • Get 2 Months Free of ASP.NET Hosting for Only $4.95/month! Receive FREE MS SQL and MySQL Databases Including ASP.NET 4/3.5, MVC 3.0, Silverlight 4, Windows 2008/IIS 7.0 Plus FREE IIS 7 Modules. Host UNLIMITED ASP.NET Web Sites - Click Here!
    ceTE software specializes in components for dynamic PDF generation and manipulation. The DynamicPDF™ product line allows you to dynamically generate PDF documents, merge PDF documents and new content to existing PDF documents from within your applications. Visit DynamicPDF here
Team Foundation Server Hosting
Become a Sponsor