Click here to Skip to main content
Click here to Skip to main content
Go to top

System Information

, 31 Jan 2013
Rate this:
Please Sign up or sign in to vote.
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 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:

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:

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 informations
            }
        }
        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:

//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:

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:

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

In “More” tap you can choose each one of Win32 classes in comboBox then DeviceInformation() function will be called and it’s input parametere will be the selected Win32 class.

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.

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 needs 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 and select them.

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:

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 aplication'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.

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.

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.

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 first part of this article but \n should be replaced by <br/> :

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:

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.Managememnt.

License

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

Share

About the Author

MehdiNaseri
Chief Technology Officer National Iranian Oil Company (NIOC)
Iran (Islamic Republic Of) Iran (Islamic Republic Of)
- Timeline of my career focus:
1994: Batch files in Microsoft Dos
1995: GW-Basic, Q Basic
1996: Assembly, C
1999: Pascal, C++
2000: Bachelor of Science Degree in Computer Software Engineering
2001: Borland Delphi, Microsoft SQL Server, HTML
2002: Visual Basic, C--, Ada, Lisp, Prolog, JavaScript
2003: C#, Java
2004: Asp.net, Computer Networks
2005: Master of Science Degree in Computer Software Engineering
2006: Data Mining
2007: XML, XQuery, XSLT
2008: WPF
2009: Silverlight, Network Administration
2010: ASP.NET MVC, JQuery, CSS, Ajax, LINQ, Entity Framework
2011: VMware Visualization (vSphere, vCenter)
2012: Microsoft SharePoint, Microsoft System Center, Microsoft Visualization (Hyper-V), Microsoft Exchange Server, Microsoft Lync, Windows 8 App
2013: Cloud Computing (VMware and Microsoft Hyper-V), Microsoft Project Server.
2014: ???

Comments and Discussions

 
QuestionGood Article Pinmemberycg16691129-Jan-13 17:48 

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

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

| Advertise | Privacy | Mobile
Web04 | 2.8.140926.1 | Last Updated 1 Feb 2013
Article Copyright 2012 by MehdiNaseri
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid