Search - Articles
DevASP.NET for ASP.NET, VB.NET, XML and C# (C-Sharp) Developers Tuesday, March 03, 2009
Dev Articles
Search Directory
ASP.NET
VB.Net
C-Sharp
SQL Server
 

Getting system information using .NET.

Author: DevASP
Download Source Code : 656_SystemInformation.zip

This article is about how you can get the system information.

The system information includes computer name, computer manufacturer, computer model, OS name, OS version, system type, total physical memory, windows directory.This is implemented by writing a class which shows you how to use WMI to get some basic system information in .NET. It demonstrates only a small subset of the features within WMI. You must include a reference to system. management to use it. Below is a description of the class and application that how you can create. 

 

Steps you will do.

 

Start visual studio and create a new window application. Set the following properties of the form object.

 

 

Name = “frmMain”

Text = “System Information”

  

 

Drop a label control on the form and set its following properties.

 

 

Name = “lblMsg”

Text = “”

Size = “520, 232”

  

 

Drop a label control on the form and set the following properties.

 

 

Name = “btnGet”

Text =”Get System Information”

  

 

Open the code window of the form and import the following namespace.

 

 

Imports System.Management

  

 

Now make a class in the same file as below. If you make this class in a separate file you should include a reference to it.  

 

 

Public Class clsWMI

        Private objOS As ManagementObjectSearcher

        Private objCS As ManagementObjectSearcher

        Private objMgmt As ManagementObject

        Private m_strComputerName As String

        Private m_strManufacturer As String

        Private m_StrModel As String

        Private m_strOSName As String

        Private m_strOSVersion As String

        Private m_strSystemType As String

        Private m_strTPM As String

        Private m_strWindowsDir As String

 

 

        Public Sub New()

 

objOS = New ManagementObjectSearcher("SELECT * FROM Win32_OperatingSystem")

 

objCS = New ManagementObjectSearcher("SELECT * FROM Win32_ComputerSystem")

 

            For Each objMgmt In objOS.Get

                m_strOSName = objMgmt("name").ToString()

                m_strOSVersion = objMgmt("version").ToString()

                m_strComputerName = objMgmt("csname").ToString()

                m_strWindowsDir = objMgmt("windowsdirectory").ToString()

            Next

 

            For Each objMgmt In objCS.Get

                m_strManufacturer = objMgmt("manufacturer").ToString()

                m_StrModel = objMgmt("model").ToString()

                m_strSystemType = objMgmt("systemtype").ToString

                m_strTPM = objMgmt("totalphysicalmemory").ToString()

            Next

 

        End Sub

 

        Public ReadOnly Property ComputerName()

            Get

                ComputerName = m_strComputerName

            End Get

        End Property

 

 

 

        Public ReadOnly Property Manufacturer()

            Get

                Manufacturer = m_strManufacturer

            End Get

        End Property

 

        Public ReadOnly Property Model()

            Get

                Model = m_StrModel

            End Get

        End Property

 

        Public ReadOnly Property OsName()

            Get

                OsName = m_strOSName

            End Get

        End Property

 

        Public ReadOnly Property OSVersion()

            Get

                OSVersion = m_strOSVersion

            End Get

        End Property

 

        Public ReadOnly Property SystemType()

            Get

                SystemType = m_strSystemType

            End Get

        End Property

 

        Public ReadOnly Property TotalPhysicalMemory()

            Get

                TotalPhysicalMemory = m_strTPM

            End Get

        End Property

 

        Public ReadOnly Property WindowsDirectory()

            Get

                WindowsDirectory = m_strWindowsDir

            End Get

        End Property

 

    End Class

 

 

Now add the following code in the click event of the button to make the object of the above class and use this class to get the system information and finally print it out on the label control.

 

 

Dim objWMI As New clsWMI

 

With objWMI

            lblMsg.Text = "Your system information is as below" + vbCrLf

            lblMsg.Text += "Computer Name = " & .ComputerName + vbCrLf

            lblMsg.Text += "Computer Manufacturer = " & .Manufacturer + vbCrLf

            lblMsg.Text += "Computer Model = " & .Model + vbCrLf

            lblMsg.Text += "OS Name = " & .OsName + vbCrLf

            lblMsg.Text += "OS Version = " & .OSVersion + vbCrLf

            lblMsg.Text += "System Type = " & .SystemType + vbCrLf

            lblMsg.Text += "Total Physical Memory = " & .TotalPhysicalMemory + vbCrLf

            lblMsg.Text += "Windows Directory = " & .WindowsDirectory + vbCrLf

End With

  

 

Run you application and click the button to get the system information.

Article Comments
This is good. But can the forum help me on this matter. I want whether Keyboard, Webcam, Printer is attached with system or not information.. Please Help me on this and kindly mail up me on this ID: cpanda@acmecollege.com

Posted on 1/29/2007 6:20:22 AM by Chandrakanta Panda

   
Add Article Comment:
Name :
Email Address :
   
Comments :
 
   
<< Creating virtual directory using .NET Framework.

Disclaimer - Privacy
© 2002-2017 DevASP.net