Click here to Skip to main content
15,860,859 members
Articles / Web Development / ASP.NET

System Information

Rate me:
Please Sign up or sign in to vote.
4.83/5 (70 votes)
31 Jan 2013CPOL4 min read 230.4K   38.1K   170   65
How to collect system information from local or remote computer

Introduction

In this application, system information has been collected by using these two class and namespace:

  1. System.Environment
  2. System.Managememnt

Using the Code

This article has been organized in three different parts:

  • System information
  • Remote computer system information
  • System information in ASP.NET

System Information

The main tab in this application has seven items:

  1. System
  2. CPU
  3. Video
  4. Local drives
  5. More
  6. Save
  7. About

In the System tab, the System.Environment class has been used to gather information:

C#
private string SystemInformation()
{
    StringBuilder StringBuilder1 = new StringBuilder(string.Empty);
    try
    {
        StringBuilder1.AppendFormat("Operation System:  {0}\n", Environment.OSVersion);
        if (Environment.Is64BitOperatingSystem)
            StringBuilder1.AppendFormat("\t\t  64 Bit Operating System\n");
        else
            StringBuilder1.AppendFormat("\t\t  32 Bit Operating System\n");
        StringBuilder1.AppendFormat("SystemDirectory:  {0}\n", Environment.SystemDirectory);
        StringBuilder1.AppendFormat("ProcessorCount:  {0}\n", Environment.ProcessorCount);
        StringBuilder1.AppendFormat("UserDomainName:  {0}\n", Environment.UserDomainName);
        StringBuilder1.AppendFormat("UserName: {0}\n", Environment.UserName);
        //Drives
        StringBuilder1.AppendFormat("LogicalDrives:\n");
        foreach (System.IO.DriveInfo DriveInfo1 in System.IO.DriveInfo.GetDrives())
        {
            try
            {
                StringBuilder1.AppendFormat("\t Drive: {0}\n\t\t VolumeLabel: " + 
                  "{1}\n\t\t DriveType: {2}\n\t\t DriveFormat: {3}\n\t\t " + 
                  "TotalSize: {4}\n\t\t AvailableFreeSpace: {5}\n",
                  DriveInfo1.Name, DriveInfo1.VolumeLabel, DriveInfo1.DriveType, 
                  DriveInfo1.DriveFormat, DriveInfo1.TotalSize, DriveInfo1.AvailableFreeSpace);
            }
            catch
            {
            }
        }
        StringBuilder1.AppendFormat("SystemPageSize:  {0}\n", Environment.SystemPageSize);
        StringBuilder1.AppendFormat("Version:  {0}", Environment.Version);
    }
    catch
    {
    }
    return StringBuilder1.ToString();
}

Result:

System Information

In the CPU, Video and Local drive tabs, the System.Management namespace has been used to gather information but before using this namespace, it has to be added to project references.

Add System.Management to references:

  1. Go to Solution Explorer.
  2. Right click on References and select Add Reference.
  3. Click on .NET tab.
  4. Select System.Management.
  5. Select the OK button.

Now we can use this namespace in the following function:

C#
private string DeviceInformation(string stringIn)
{
    StringBuilder StringBuilder1 = new StringBuilder(string.Empty);
    ManagementClass ManagementClass1 = new ManagementClass(stringIn);
    //Create a ManagementObjectCollection to loop through
    ManagementObjectCollection ManagemenobjCol = ManagementClass1.GetInstances();
    //Get the properties in the class
    PropertyDataCollection properties = ManagementClass1.Properties;
    foreach (ManagementObject obj in ManagemenobjCol)
    {
        foreach (PropertyData property in properties)
        {
            try
            {
                StringBuilder1.AppendLine(property.Name + ":  " + 
                  obj.Properties[property.Name].Value.ToString());
            }
            catch
            {
                //Add codes to manage more information
            }
        }
        StringBuilder1.AppendLine();
    }
    return StringBuilder1.ToString();
}

Notice that this function has an input string which is a Win32 class such as Win32_Processor or Win32_LogicalDisk. We use the first one for collecting information about CPU and the second one for local drives.

DeviceInformation("Win32_Processor")

CPU Information

DeviceInformation("Win32_VideoController")

Local Drives Information

DeviceInformation("Win32_LogicalDisk")

Local Drives Information

Now in the Window_Loaded event, we call these functions:

C#
//System Information
textBox1.Text = SystemInformation();
//CPU Information
textBox2.Text = DeviceInformation("Win32_Processor");
//Local Drives Information
textBox3.Text = DeviceInformation("Win32_LogicalDisk");
//Video Controller Information
textBox4.Text = DeviceInformation("Win32_VideoController");

You can use DeviceInformation() with all Win32 classes. Win32 classes are in seven different categories which are: Computer System Hardware, Installed Applications, Operating System, Performance Counter, Security Descriptor Helper and WMI Service Management.

List of Win32 classes used in this application are given below:

Win32_1394Controller
Win32_1394ControllerDevice
Win32_AccountSID
Win32_ActionCheck
Win32_ActiveRoute
Win32_AllocatedResource
Win32_ApplicationCommandLine
Win32_ApplicationService
Win32_AssociatedBattery
Win32_AssociatedProcessorMemory
Win32_AutochkSetting
Win32_BaseBoard
Win32_Battery
Win32_Binary
Win32_BindImageAction
Win32_BIOS
Win32_BootConfiguration
Win32_Bus Win32_CacheMemory
Win32_CDROMDrive
Win32_CheckCheck
Win32_CIMLogicalDeviceCIMDataFile
Win32_ClassicCOMApplicationClasses
Win32_ClassicCOMClass
Win32_ClassicCOMClassSetting
Win32_ClassicCOMClassSettings
Win32_ClassInforAction
Win32_ClientApplicationSetting
Win32_CodecFile
Win32_COMApplicationSettings
Win32_COMClassAutoEmulator
Win32_ComClassEmulator
Win32_CommandLineAccess
Win32_ComponentCategory
Win32_ComputerSystem
Win32_ComputerSystemProcessor
Win32_ComputerSystemProduct
Win32_ComputerSystemWindowsProductActivationSetting
Win32_Condition
Win32_ConnectionShare
Win32_ControllerHastHub
Win32_CreateFolderAction
Win32_CurrentProbe
Win32_DCOMApplication
Win32_DCOMApplicationAccessAllowedSetting
Win32_DCOMApplicationLaunchAllowedSetting
Win32_DCOMApplicationSetting
Win32_DependentService
Win32_Desktop
Win32_DesktopMonitor
Win32_DeviceBus
Win32_DeviceMemoryAddress
Win32_Directory
Win32_DirectorySpecification
Win32_DiskDrive
Win32_DiskDrivePhysicalMedia
Win32_DiskDriveToDiskPartition
Win32_DiskPartition
Win32_DiskQuota
Win32_DisplayConfiguration
Win32_DisplayControllerConfiguration
Win32_DMAChanner
Win32_DriverForDevice
Win32_DriverVXD
Win32_DuplicateFileAction
Win32_Environment
Win32_EnvironmentSpecification
Win32_ExtensionInfoAction
Win32_Fan
Win32_FileSpecification
Win32_FloppyController
Win32_FloppyDrive
Win32_FontInfoAction
Win32_Group
Win32_GroupDomain
Win32_GroupUser
Win32_HeatPipe
Win32_IDEController
Win32_IDEControllerDevice
Win32_ImplementedCategory
Win32_InfraredDevice
Win32_IniFileSpecification
Win32_InstalledSoftwareElement
Win32_IP4PersistedRouteTable
Win32_IP4RouteTable
Win32_IRQResource
Win32_Keyboard
Win32_LaunchCondition
Win32_LoadOrderGroup
Win32_LoadOrderGroupServiceDependencies
Win32_LoadOrderGroupServiceMembers
Win32_LocalTime
Win32_LoggedOnUser
Win32_LogicalDisk
Win32_LogicalDiskRootDirectory
Win32_LogicalDiskToPartition
Win32_LogicalFileAccess
Win32_LogicalFileAuditing
Win32_LogicalFileGroup
Win32_LogicalFileOwner
Win32_LogicalFileSecuritySetting
Win32_LogicalMemoryConfiguration
Win32_LogicalProgramGroup
Win32_LogicalProgramGroupDirectory
Win32_LogicalProgramGroupItem
Win32_LogicalProgramGroupItemDataFile
Win32_LogicalShareAccess
Win32_LogicalShareAuditing
Win32_LogicalShareSecuritySetting
Win32_LogonSession
Win32_LogonSessionMappedDisk
Win32_MappedLogicalDisk
Win32_MemoryArray
Win32_MemoryArrayLocation
Win32_MemoryDevice
Win32_MemoryDeviceArray
Win32_MemoryDeviceLocation
Win32_MIMEInfoAction
Win32_MotherboardDevice
Win32_MoveFileAction
Win32_NamedJobObject
Win32_NamedJobObjectActgInfo
Win32_NamedJobObjectLimit
Win32_NamedJobObjectLimitSetting
Win32_NamedJobObjectProcess
Win32_NamedJobObjectSecLimit
Win32_NamedJobObjectSecLimitSetting
Win32_NamedJobObjectStatistics
Win32_NetworkAdapter
Win32_NetworkAdapterConfiguration
Win32_NetworkAdapterSetting
Win32_NetworkClient
Win32_NetworkConnection
Win32_NetworkLoginProfile
Win32_NetworkProtocol
Win32_NTDomain
Win32_NTEventlogFile
Win32_NTLogEvent
Win32_NTLogEventComputer
Win32_NTLogEvnetLog
Win32_NTLogEventUser
Win32_ODBCAttribute
Win32_ODBCDataSourceAttribute
Win32_ODBCDataSourceSpecification
Win32_ODBCDriverAttribute
Win32_ODBCDriverSoftwareElement
Win32_ODBCDriverSpecification
Win32_ODBCSourceAttribute
Win32_ODBCTranslatorSpecification
Win32_OnBoardDevice
Win32_OperatingSystem
Win32_OperatingSystemAutochkSetting
Win32_OperatingSystemQFE
Win32_OSRecoveryConfiguración
Win32_PageFile
Win32_PageFileElementSetting
Win32_PageFileSetting
Win32_PageFileUsage
Win32_ParallelPort
Win32_Patch
Win32_PatchFile
Win32_PatchPackage
Win32_PCMCIAControler
Win32_PerfFormattedData_ASP_ActiveServerPages
Win32_PerfFormattedData_ASPNET_114322_ASPNETAppsv114322
Win32_PerfFormattedData_ASPNET_114322_ASPNETv114322
Win32_PerfFormattedData_ASPNET_2040607_ASPNETAppsv2040607
Win32_PerfFormattedData_ASPNET_2040607_ASPNETv2040607
Win32_PerfFormattedData_ASPNET_ASPNET
Win32_PerfFormattedData_ASPNET_ASPNETApplications
Win32_PerfFormattedData_aspnet_state_ASPNETStateService
Win32_PerfFormattedData_ContentFilter_IndexingServiceFilter
Win32_PerfFormattedData_ContentIndex_IndexingService
Win32_PerfFormattedData_DTSPipeline_SQLServerDTSPipeline
Win32_PerfFormattedData_Fax_FaxServices
Win32_PerfFormattedData_InetInfo_InternetInformationServicesGlobal
Win32_PerfFormattedData_ISAPISearch_HttpIndexingService
Win32_PerfFormattedData_MSDTC_DistributedTransactionCoordinator
Win32_PerfFormattedData_NETCLRData_NETCLRData
Win32_PerfFormattedData_NETCLRNetworking_NETCLRNetworking
Win32_PerfFormattedData_NETDataProviderforOracle_NETCLRData
Win32_PerfFormattedData_NETDataProviderforSqlServer_NETDataProviderforSqlServer
Win32_PerfFormattedData_NETFramework_NETCLRExceptions
Win32_PerfFormattedData_NETFramework_NETCLRInterop
Win32_PerfFormattedData_NETFramework_NETCLRJit
Win32_PerfFormattedData_NETFramework_NETCLRLoading
Win32_PerfFormattedData_NETFramework_NETCLRLocksAndThreads
Win32_PerfFormattedData_NETFramework_NETCLRMemory
Win32_PerfFormattedData_NETFramework_NETCLRRemoting
Win32_PerfFormattedData_NETFramework_NETCLRSecurity
Win32_PerfFormattedData_NTFSDRV_ControladordealmacenamientoNTFSdeSMTP
Win32_PerfFormattedData_Outlook_Outlook
Win32_PerfFormattedData_PerfDisk_LogicalDisk
Win32_PerfFormattedData_PerfDisk_PhysicalDisk
Win32_PerfFormattedData_PerfNet_Browser
Win32_PerfFormattedData_PerfNet_Redirector
Win32_PerfFormattedData_PerfNet_Server
Win32_PerfFormattedData_PerfNet_ServerWorkQueues
Win32_PerfFormattedData_PerfOS_Cache
Win32_PerfFormattedData_PerfOS_Memory
Win32_PerfFormattedData_PerfOS_Objects
Win32_PerfFormattedData_PerfOS_PagingFile
Win32_PerfFormattedData_PerfOS_Processor
Win32_PerfFormattedData_PerfOS_System
Win32_PerfFormattedData_PerfProc_FullImage_Costly
Win32_PerfFormattedData_PerfProc_Image_Costly
Win32_PerfFormattedData_PerfProc_JobObject
Win32_PerfFormattedData_PerfProc_JobObjectDetails
Win32_PerfFormattedData_PerfProc_Process
Win32_PerfFormattedData_PerfProc_ProcessAddressSpace_Costly
Win32_PerfFormattedData_PerfProc_Thread
Win32_PerfFormattedData_PerfProc_ThreadDetails_Costly
Win32_PerfFormattedData_RemoteAccess_RASPort
Win32_PerfFormattedData_RemoteAccess_RASTotal
Win32_PerfFormattedData_RSVP_RSVPInterfaces
Win32_PerfFormattedData_RSVP_RSVPService
Win32_PerfFormattedData_Spooler_PrintQueue
Win32_PerfFormattedData_TapiSrv_Telephony
Win32_PerfFormattedData_Tcpip_ICMP
Win32_PerfFormattedData_Tcpip_IP
Win32_PerfFormattedData_Tcpip_NBTConnection
Win32_PerfFormattedData_Tcpip_NetworkInterface
Win32_PerfFormattedData_Tcpip_TCP
Win32_PerfFormattedData_Tcpip_UDP
Win32_PerfFormattedData_TermService_TerminalServices
Win32_PerfFormattedData_TermService_TerminalServicesSession
Win32_PerfFormattedData_W3SVC_WebService
Win32_PerfRawData_ASP_ActiveServerPages
Win32_PerfRawData_ASPNET_114322_ASPNETAppsv114322
Win32_PerfRawData_ASPNET_114322_ASPNETv114322
Win32_PerfRawData_ASPNET_2040607_ASPNETAppsv2040607
Win32_PerfRawData_ASPNET_2040607_ASPNETv2040607
Win32_PerfRawData_ASPNET_ASPNET
Win32_PerfRawData_ASPNET_ASPNETApplications
Win32_PerfRawData_aspnet_state_ASPNETStateService
Win32_PerfRawData_ContentFilter_IndexingServiceFilter
Win32_PerfRawData_ContentIndex_IndexingService
Win32_PerfRawData_DTSPipeline_SQLServerDTSPipeline
Win32_PerfRawData_Fax_FaxServices
Win32_PerfRawData_InetInfo_InternetInformationServicesGlobal
Win32_PerfRawData_ISAPISearch_HttpIndexingService
Win32_PerfRawData_MSDTC_DistributedTransactionCoordinator
Win32_PerfRawData_NETCLRData_NETCLRData
Win32_PerfRawData_NETCLRNetworking_NETCLRNetworking
Win32_PerfRawData_NETDataProviderforOracle_NETCLRData
Win32_PerfRawData_NETDataProviderforSqlServer_NETDataProviderforSqlServer
Win32_PerfRawData_NETFramework_NETCLRExceptions
Win32_PerfRawData_NETFramework_NETCLRInterop
Win32_PerfRawData_NETFramework_NETCLRJit
Win32_PerfRawData_NETFramework_NETCLRLoading
Win32_PerfRawData_NETFramework_NETCLRLocksAndThreads
Win32_PerfRawData_NETFramework_NETCLRMemory
Win32_PerfRawData_NETFramework_NETCLRRemoting
Win32_PerfRawData_NETFramework_NETCLRSecurity
Win32_PerfRawData_NTFSDRV_ControladordealmacenamientoNTFSdeSMTP
Win32_PerfRawData_Outlook_Outlook
Win32_PerfRawData_PerfDisk_LogicalDisk
Win32_PerfRawData_PerfDisk_PhysicalDisk
Win32_PerfRawData_PerfNet_Browser
Win32_PerfRawData_PerfNet_Redirector
Win32_PerfRawData_PerfNet_Server
Win32_PerfRawData_PerfNet_ServerWorkQueues
Win32_PerfRawData_PerfOS_Cache
Win32_PerfRawData_PerfOS_Memory
Win32_PerfRawData_PerfOS_Objects
Win32_PerfRawData_PerfOS_PagingFile
Win32_PerfRawData_PerfOS_Processor
Win32_PerfRawData_PerfOS_System
Win32_PerfRawData_PerfProc_FullImage_Costly
Win32_PerfRawData_PerfProc_Image_Costly
Win32_PerfRawData_PerfProc_JobObject
Win32_PerfRawData_PerfProc_JobObjectDetails
Win32_PerfRawData_PerfProc_Process
Win32_PerfRawData_PerfProc_ProcessAddressSpace_Costly
Win32_PerfRawData_PerfProc_Thread
Win32_PerfRawData_PerfProc_ThreadDetails_Costly
Win32_PerfRawData_RemoteAccess_RASPort
Win32_PerfRawData_RemoteAccess_RASTotal
Win32_PerfRawData_RSVP_RSVPInterfaces
Win32_PerfRawData_RSVP_RSVPService
Win32_PerfRawData_Spooler_PrintQueue
Win32_PerfRawData_TapiSrv_Telephony
Win32_PerfRawData_Tcpip_ICMP
Win32_PerfRawData_Tcpip_IP
Win32_PerfRawData_Tcpip_NBTConnection
Win32_PerfRawData_Tcpip_NetworkInterface
Win32_PerfRawData_Tcpip_TCP
Win32_PerfRawData_Tcpip_UDP
Win32_PerfRawData_TermService_TerminalServices
Win32_PerfRawData_TermService_TerminalServicesSession
Win32_PerfRawData_W3SVC_WebService
Win32_PhysicalMedia
Win32_PhysicalMemory
Win32_PhysicalMemoryArray
Win32_PhysicalMemoryLocation
Win32_PingStatus
Win32_PNPAllocatedResource
Win32_PnPDevice
Win32_PnPEntity
Win32_PnPSignedDriver
Win32_PnPSignedDriverCIMDataFile
Win32_PointingDevice
Win32_PortableBattery
Win32_PortConnector
Win32_PortResource
Win32_POTSModem
Win32_POTSModemToSerialPort
Win32_Printer
Win32_PrinterConfiguration
Win32_PrinterController
Win32_PrinterDriver
Win32_PrinterDriverDll
Win32_PrinterSetting
Win32_PrinterShare
Win32_PrintJob
Win32_Process
Win32_Processor
Win32_Product
Win32_ProductCheck
Win32_ProductResource
Win32_ProductSoftwareFeatures
Win32_ProgIDSpecification
Win32_ProgramGroup
Win32_ProgramGroupContents
Win32_Property
Win32_ProtocolBinding
Win32_Proxy
Win32_PublishComponentAction
Win32_QuickFixEngineering
Win32_QuotaSetting
Win32_Refrigeration
Win32_Registry
Win32_RegistryAction
Win32_RemoveFileAction
Win32_RemoveIniAction
Win32_ReserveCost
Win32_ScheduledJob
Win32_SCSIController
Win32_SCSIControllerDevice
Win32_SecuritySettingOfLogicalFile
Win32_SecuritySettingOfLogicalShare
Win32_SelfRegModuleAction
Win32_SerialPort
Win32_SerialPortConfiguration
Win32_SerialPortSetting
Win32_ServerConnection
Win32_ServerSession
Win32_Service
Win32_ServiceControl
Win32_ServiceSpecification
Win32_ServiceSpecificationService
Win32_SessionConnection
Win32_SessionProcess
Win32_Share
Win32_ShareToDirectory
Win32_ShortcutAction
Win32_ShortcutFile
Win32_ShortcutSAP
Win32_SID
Win32_SoftwareElement
Win32_SoftwareElementAction
Win32_SoftwareElementCheck
Win32_SoftwareElementCondition
Win32_SoftwareElementResource
Win32_SoftwareFeature
Win32_SoftwareFeatureAction
Win32_SoftwareFeatureCheck
Win32_SoftwareFeatureParent
Win32_SoftwareFeatureSoftwareElements
Win32_SoundDevice
Win32_StartupCommand
Win32_SubDirectory
Win32_SystemAccount
Win32_SystemBIOS
Win32_SystemBootConfiguration
Win32_SystemDesktop
Win32_SystemDevices
Win32_SystemDriver
Win32_SystemDriverPNPEntity
Win32_SystemEnclosure
Win32_SystemLoadOrderGroups
Win32_SystemLogicalMemoryConfiguration
Win32_SystemNetworkConnections
Win32_SystemOperatingSystem
Win32_SystemPartitions
Win32_SystemProcesses
Win32_SystemProgramGroups
Win32_SystemResources
Win32_SystemServices
Win32_SystemSlot
Win32_SystemSystemDriver
Win32_SystemTimeZone
Win32_SystemUsers
Win32_TapeDrive
Win32_TCPIPPrinterPort
Win32_TemperatureProbe
Win32_Terminal
Win32_TerminalService
Win32_TerminalServiceSetting
Win32_TerminalServiceToSetting
Win32_TerminalTerminalSetting
Win32_Thread
Win32_TimeZone
Win32_TSAccount
Win32_TSClientSetting
Win32_TSEnvironmentSetting
Win32_TSGeneralSetting
Win32_TSLogonSetting
Win32_TSNetworkAdapterListSetting
Win32_TSNetworkAdapterSetting
Win32_TSPermissionsSetting
Win32_TSRemoteControlSetting
Win32_TSSessionDirectory
Win32_TSSessionDirectorySetting
Win32_TSSessionSetting
Win32_TypeLibraryAction
Win32_UninterruptiblePowerSupply
Win32_USBController
Win32_USBControllerDevice
Win32_USBHub
Win32_UserAccount
Win32_UserDesktop
Win32_UserInDomain
Win32_UTCTime
Win32_VideoController
Win32_VideoSettings
Win32_VoltageProbe
Win32_VolumeQuotaSetting
Win32_WindowsProductActivation
Win32_WMIElementSetting
Win32_WMISetting

This is how we fill comboBox with Win32 classes:

C#
foreach (string stringWin32class in stringWin32classes)
{
    //comboBox in more tab
    comboBox1.Items.Add(stringWin32class);
}

In “More” tab, you can choose each one of Win32 classes in comboBox, then DeviceInformation() function will be called and its input parameter will be the selected Win32 class.

C#
private void comboBox1_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
    textBox5.Text = DeviceInformation(comboBox1.SelectedItem.ToString());
    //Enable Save Button
    button1.IsEnabled = true;
}

Finally, information about that class will be shown in the textbox in that tab.

System Information

You can also save the result in text file by clicking on save button.

C#
private void button1_Click(object sender, RoutedEventArgs e)
{
    this.Cursor = Cursors.AppStarting;
    button2.IsEnabled = false;
    Microsoft.Win32.SaveFileDialog SaveFileDialog1 = new Microsoft.Win32.SaveFileDialog();
    SaveFileDialog1.Filter = "txt files (*.txt)|*.txt";
    if ((bool)SaveFileDialog1.ShowDialog())
    {
        using (System.IO.StreamWriter StreamWriter1 = 
                    new System.IO.StreamWriter(SaveFileDialog1.OpenFile()))
        {
            StreamWriter1.WriteLine("\n:::::::::::::::::{0}::::::::::::::::::", 
                                    comboBox1.SelectedItem.ToString());
            StreamWriter1.WriteLine(textBox5.Text);
            StreamWriter1.Close();
        }
        MessageBox.Show("File saved successfully", "System Information", 
          MessageBoxButton.OK, MessageBoxImage.Information);
    }
    this.Cursor = Cursors.Arrow;
    button2.IsEnabled = true;
}

If you want to save information from different classes, you can use save tab. In this tab from listbox, you can select a few classes and the result will be saved in selected text file. You can also save information from all classes but this task might need a few hours to be finished and you shouldn’t choose this one except you know what you are doing. To do this, at first, we need a listBox which is filled by checkboxes and each one is a Win32 class. So users can select them.

C#
foreach (string stringWin32class in stringWin32classes)
{
    //listBox in Save tab 
    CheckBox CheckBox1 = new CheckBox();
    CheckBox1.Content = stringWin32class;
    listBox1.Items.Add(CheckBox1);
}

System Information

This is how we save information about all selected Win32 classes:

C#
private void button2_Click(object sender, RoutedEventArgs e)
{
    this.Cursor = Cursors.AppStarting;
    button2.IsEnabled = false;
    progressBar1.Value = 0;
    Microsoft.Win32.SaveFileDialog SaveFileDialog1 = new Microsoft.Win32.SaveFileDialog();
    SaveFileDialog1.Filter = "txt files (*.txt)|*.txt";
    if ((bool)SaveFileDialog1.ShowDialog())
    {
        using (System.IO.StreamWriter StreamWriter1 = 
               new System.IO.StreamWriter(SaveFileDialog1.OpenFile()))
        {
            if (radioButton1.IsChecked == true)
            {
                int i = 0;
                foreach (string stringWin32class in stringWin32classes)
                {
                    StreamWriter1.WriteLine("\n:::::::::::::::::{0}::::::::::::::::::", 
                                            stringWin32class);
                    StreamWriter1.WriteLine(DeviceInformation(stringWin32class));
                    progressBar1.Value = (++i * 100 / 443);
                }
                StreamWriter1.Close();
            }
            else
            {
                int intIncrement=0,intCount = 0;
                foreach (CheckBox CheckBox1 in listBox1.Items)
                {
                    if (CheckBox1.IsChecked == true)
                    {
                        intCount++;
                    }
                }
                foreach (CheckBox CheckBox1 in listBox1.Items)
                {
                    if (CheckBox1.IsChecked == true)
                    {
                        StreamWriter1.WriteLine("\n:::::::::::::::::{0}::::::::::::::::::", 
                                                CheckBox1.Content.ToString());
                        StreamWriter1.WriteLine
                                      (DeviceInformation(CheckBox1.Content.ToString()));
                        intIncrement++;
                        progressBar1.Value = (intIncrement * 100 / intCount);
                        MessageBox.Show(intIncrement.ToString());
                        MessageBox.Show(progressBar1.Value.ToString());
                    }
                }
                StreamWriter1.Close();
            }
            MessageBoxResult result = MessageBox.Show("File saved successfully", 
              "System Information", MessageBoxButton.OK, MessageBoxImage.Information);
        }
    }
    progressBar1.Value = 0;
    this.Cursor = Cursors.Arrow;
    button2.IsEnabled = true;
}

Remote Computer System Information

With System.Management namespace, we can take system information of a remote computer. First, we should make a WMI connection. As you can see in application's snapshot, we need IP address, username and password of that computer. You can use any local account on that computer or even Active Directory accounts which have access permission on that computer. Instead of IP address of remote computer, you can use computer name too.

Image 7

Before using System.Management, we have to initialize a new instance of ManagementScope and also specify required connection setting in ConnectionOptions to make a WMI connection.

C#
private void RemoteComputerInfo(string strUsername, string strPassword, 
                   string strIP, ListBox ListBoxIn, string stringWin32class)
{
    ListBox ListBoxResult = ListBoxIn;
    ListBoxResult.Items.Clear();

    ConnectionOptions options = new ConnectionOptions();
    options.Username = strUsername;
    options.Password = strPassword;
    options.Impersonation = ImpersonationLevel.Impersonate;
    options.EnablePrivileges = true;
    try
    {
        ManagementScope ManagementScope1 = new ManagementScope
                   (string.Format("\\\\{0}\\root\\cimv2", strIP), options);
        ManagementScope1.Connect();

        ObjectGetOptions objectGetOptions = new ObjectGetOptions();
        ManagementPath managementPath1 = new ManagementPath(stringWin32class);
        ManagementClass ManagementClass1 = 
            new ManagementClass(ManagementScope1, managementPath1, objectGetOptions);

        PropertyDataCollection PropertyDataCollection1 = ManagementClass1.Properties;

        foreach (ManagementObject ManagementObject1 in ManagementClass1.GetInstances())
        {
            foreach (PropertyData property in PropertyDataCollection1)
            {
                    try
                {
                    // Display the remote computer system information in input listbox
                    ListBoxResult.Items.Add(string.Format(property.Name + ":  " + 
                      ManagementObject1.Properties[property.Name].Value.ToString()));
                }
                catch
                {
                }
            }
        }
    }
    catch (Exception ex)
    {
        ListBoxResult.Items.Add(string.Format
                ("Can't Connect to Server: {0}\n{1}", strIP,ex.Message));
    }
}

This application displays a lot of information about hardware and software of that system but some of them might be more important for you. So it is better to find and display those ones in another function. In this example, we only display some data about operation system. You can add everything you want in the same way.

C#
private void RemoteComputerInfoCustomized
    (string strUsername, string strPassword, string strIP, ListBox ListBoxIn)
{
    ListBox ListBoxResult = ListBoxIn;
    ListBoxResult.Items.Clear();

    ConnectionOptions options = new ConnectionOptions();
    options.Username = strUsername;
    options.Password = strPassword;
    options.Impersonation = ImpersonationLevel.Impersonate;
    options.EnablePrivileges = true;
    try
    {
        ManagementScope ManagementScope1 = new ManagementScope
                 (string.Format("\\\\{0}\\root\\cimv2", strIP), options);
        ManagementScope1.Connect();
        ObjectGetOptions objectGetOptions = new ObjectGetOptions();
        ManagementPath managementPath1 = new ManagementPath("Win32_OperatingSystem");
        ManagementClass ManagementClass1 = 
             new ManagementClass(ManagementScope1, managementPath1, objectGetOptions);

        foreach (ManagementObject ManagementObject1 in ManagementClass1.GetInstances())
        {
            // Display the remote computer information
            ListBoxResult.Items.Add(string.Format
                   ("Computer Name : {0}", ManagementObject1["csname"]));
            ListBoxResult.Items.Add(string.Format
                   ("Windows Directory : {0}", ManagementObject1["WindowsDirectory"]));
            ListBoxResult.Items.Add(string.Format
                   ("Operating System: {0}", ManagementObject1["Caption"]));
            ListBoxResult.Items.Add(string.Format
                   ("Version: {0}", ManagementObject1["Version"]));
            ListBoxResult.Items.Add(string.Format
                   ("Manufacturer : {0}", ManagementObject1["Manufacturer"]));
            ListBoxResult.Items.Add(string.Format
                   ("Latest bootup time : {0}", ManagementObject1["LastBootUpTime"]));
        }
    }
    catch (Exception ex)
    {
        ListBoxResult.Items.Add(string.Format
                  ("Can't Connect to Server: {0}\n{1}", strIP,ex.Message));
    }
}

Using System.Environment in ASP Pages

System.Environment also can be used in ASP pages to collect data about web server. We use SystemInformation() function like we used it in the first part of this article but \n should be replaced by <br/>:

C#
private string SystemInformation()
{
    StringBuilder StringBuilder1 = new StringBuilder(string.Empty);
    try
    {
        StringBuilder1.AppendFormat("Operation System: {0}<br/>", Environment.OSVersion);
        if (Environment.Is64BitOperatingSystem)
            StringBuilder1.AppendFormat("64 Bit Operating System<br/>");
        else
            StringBuilder1.AppendFormat("32 Bit Operating System<br/>");
        StringBuilder1.AppendFormat("SystemDirectory: {0}<br/>", Environment.SystemDirectory);
        StringBuilder1.AppendFormat("ProcessorCount: {0}<br/>", Environment.ProcessorCount);
        StringBuilder1.AppendFormat("UserDomainName: {0}<br/>", Environment.UserDomainName);
        StringBuilder1.AppendFormat("UserName: {0}<br>", Environment.UserName);
        //Drives
        StringBuilder1.AppendFormat("LogicalDrives:<br>");
        foreach (System.IO.DriveInfo DriveInfo1 in System.IO.DriveInfo.GetDrives())
        {
            try
            {
                StringBuilder1.AppendFormat("Drive: {0}<br/>VolumeLabel: 
                          {1}<br/>DriveType: {2}<br/>DriveFormat: " + 
                    "{3}<br/>TotalSize: {4}<br/>AvailableFreeSpace: {5}<br/>",
                    DriveInfo1.Name, DriveInfo1.VolumeLabel, DriveInfo1.DriveType, 
                    DriveInfo1.DriveFormat, DriveInfo1.TotalSize, 
                    DriveInfo1.AvailableFreeSpace);
            }
            catch
            {
            }
        }
        StringBuilder1.AppendFormat("SystemPageSize: {0}<br/>", Environment.SystemPageSize);
        StringBuilder1.AppendFormat("Version: {0}", Environment.Version);
    }
    catch
    {
    }
    return StringBuilder1.ToString();
}

Then you can use the code like before:

C#
Label1.Text = "SystemInformation:<br/>" + SystemInformation();

Result in web page:

Users System ASP

Now you can save these data to your database.

Points of Interest

In this article, you learned how to collect system information about local or remote computer by using System.Environment and System.Management.

History

  • 1st February, 2013: Initial version

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer (Senior) Amazon AWS
Canada Canada
• MCSD (Microsoft Certified Solutions Developer): App Builder
• MCSD (Microsoft Certified Solutions Developer): Web Applications
• MCSA (Microsoft Certified Solutions Associate): Universal Windows Platform
• MCP (Microsoft Certified Professional)

• PMI-PBA (PMI Professional in Business Analysis)
• PMI-ACP (PMI Agile Certified Practitioner)
• PMP (Project Management Professional)

Comments and Discussions

 
QuestionUpdated Version > VB.NET? Pin
Member 1303204714-Oct-22 9:29
Member 1303204714-Oct-22 9:29 
Questionhow to store all this data in database? Pin
Member 156898527-Jul-22 22:54
Member 156898527-Jul-22 22:54 
Questiondata store in database Pin
Member 156898525-Jul-22 4:04
Member 156898525-Jul-22 4:04 
PraiseBeen looking at WPF for this exact purpose - nicely done! Pin
Member 1462539516-Oct-19 14:51
Member 1462539516-Oct-19 14:51 
QuestionFilling ComboBox Pin
Member 1455786615-Aug-19 1:13
Member 1455786615-Aug-19 1:13 
QuestionSYSTEM HARDWARE INFO Pin
Member 138637997-Jun-18 20:26
Member 138637997-Jun-18 20:26 
QuestionQuery USB Hub consuming bandwidth Pin
Member 121305497-May-16 15:07
Member 121305497-May-16 15:07 
GeneralMy vote of 5 Pin
Member 121173586-Nov-15 5:01
Member 121173586-Nov-15 5:01 
QuestionGreat article Pin
Troy compton27-Mar-15 9:56
Troy compton27-Mar-15 9:56 
GeneralMy vote of 5 Pin
Kuthuparakkal21-Feb-15 5:44
Kuthuparakkal21-Feb-15 5:44 
QuestionNeed this in .Net Framework 4.0 Pin
Shagun Bansal17-Feb-14 4:50
Shagun Bansal17-Feb-14 4:50 
Questionمرسی Pin
Ehsan Faramarzi28-Jan-14 22:37
Ehsan Faramarzi28-Jan-14 22:37 
AnswerRe: مرسی Pin
MehdiNaseri30-Jan-14 0:21
professionalMehdiNaseri30-Jan-14 0:21 
QuestionAbout: System Information Pin
FlashBond1-Oct-13 2:28
FlashBond1-Oct-13 2:28 
AnswerRe: About: System Information Pin
MehdiNaseri30-Jan-14 1:01
professionalMehdiNaseri30-Jan-14 1:01 
QuestionSearching for specfic files Pin
M i s t e r L i s t e r27-Jun-13 6:19
M i s t e r L i s t e r27-Jun-13 6:19 
AnswerRe: Searching for specfic files Pin
MehdiNaseri22-Jul-13 13:36
professionalMehdiNaseri22-Jul-13 13:36 
GeneralMy vote of 4 Pin
Member 43208448-Feb-13 6:44
Member 43208448-Feb-13 6:44 
GeneralRe: My vote of 4 Pin
MehdiNaseri8-Feb-13 11:44
professionalMehdiNaseri8-Feb-13 11:44 
GeneralMy vote of 3 Pin
Country Man7-Feb-13 23:30
Country Man7-Feb-13 23:30 
Generalmy comment Pin
moeinmohebbi4-Feb-13 21:41
moeinmohebbi4-Feb-13 21:41 
GeneralRe: my comment Pin
MehdiNaseri5-Feb-13 14:31
professionalMehdiNaseri5-Feb-13 14:31 
QuestionGood Article Pin
ycg16691129-Jan-13 17:48
ycg16691129-Jan-13 17:48 
QuestionDirectX Version Pin
fmaeseel26-Jan-13 21:30
fmaeseel26-Jan-13 21:30 
AnswerRe: DirectX Version Pin
MehdiNaseri28-Jan-13 3:53
professionalMehdiNaseri28-Jan-13 3:53 

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.