What is WMI classes and purpose and where applicable.


WMI
Windows Management Instrumentation (WMI) is a set of extensions to the Windows Driver Model that provides an operating system interface through which instrumented components provide information and notification.

Purpose
Windows Management Instrumentation (WMI) is the infrastructure for management data and operations on Windows-based operating systems. You can write WMI scripts or applications to automate administrative tasks on remote computers.

Where applicable
WMI can be used in all Windows-based applications, and is most useful in enterprise applications and administrative scripts.

How to get Operating System and Computer Name
Operating System and Computer Name can be found in “Win32_OperatingSystem” class.

            ManagementNamedValueCollection mContext = new ManagementNamedValueCollection();
            mContext.Add("__ProviderArchitecture", 64);
            mContext.Add("__RequiredArchitecture", false);
            ConnectionOptions options = new ConnectionOptions           
            options.Impersonation = ImpersonationLevel.Impersonate;
            options.EnablePrivileges = true;
            options.Context = mContext;
            string strIP="IP Address";
            string sOperatingSystem ="";
            string sComputerName ="";
            try
            {
                ManagementScope ManagementScope1 = new ManagementScope(string.Format("\\\\{0}\\root\\cimv2", strIP), options);
                ManagementScope1.Connect();
                ObjectGetOptions objectGetOptions = new ObjectGetOptions();
                try
                {
                    ManagementPath mpWin32_OperatingSystem = new ManagementPath("Win32_OperatingSystem");
                    ManagementClass mcWin32_OperatingSystem = new ManagementClass(ManagementScope1, mpWin32_OperatingSystem, objectGetOptions);
                    foreach (ManagementObject moWin32_OperatingSystem in mcWin32_OperatingSystem.GetInstances())
                    {
                        sOperatingSystem = moWin32_OperatingSystem["Caption"].ToString();                        
                        sComputerName = moWin32_OperatingSystem["csname"].ToString();                        
                    }
                }
                catch (Exception ex)
                {                    
                }

How to get OS Architecture, Model No and RAM.
OS Architecture, Model No and RAM can be found in “Win32_ComputerSystem” class.

                    ManagementPath mpWin32_ComputerSystem = new ManagementPath("Win32_ComputerSystem");
                    ManagementClass mcWin32_ComputerSystem = new ManagementClass(ManagementScope1, mpWin32_ComputerSystem, objectGetOptions);
                    string sOSArchitecture ="";
                    string sModelNo ="";
                    string sRAM ="";
                    foreach (ManagementObject moWin32_ComputerSystem in mcWin32_ComputerSystem.GetInstances())
                    {
                        if (objAssetInfo.sOperatingSystem == "Microsoft Windows XP Professional")
                        {
                            sOSArchitecture = "(32-bit)";
                            Regex TypeMatch = new Regex("(x64)");
                            string CSystemType = moWin32_ComputerSystem["SystemType"].ToString();
                            if (TypeMatch.Match(CSystemType).Success)
                            {
                                sOSArchitecture = "(64-bit)";
                            }
                        }
                        sModelNo = moWin32_ComputerSystem["Model"].ToString();
                        sRAM = Math.Round((Convert.ToInt64(moWin32_ComputerSystem["TotalPhysicalMemory"]) * 1.00 / 1024 / 1024 / 1024), 2).ToString() + " GB";

If sOperatingSystem != “Microsoft Windows XP Professional” then OSArchitecture will be found in “Win32_OperatingSystem” class.

                    ManagementPath mpWin32_OperatingSystem = new ManagementPath("Win32_OperatingSystem");
                    ManagementClass mcWin32_OperatingSystem = new ManagementClass(ManagementScope1, mpWin32_OperatingSystem, objectGetOptions);
                    foreach (ManagementObject moWin32_OperatingSystem in mcWin32_OperatingSystem.GetInstances())
                    {
                       string sOperatingSystem = moWin32_OperatingSystem["Caption"].ToString();
                        if (sOperatingSystem != "Microsoft Windows XP Professional")
                        {
                            OSArchitecture = "(" + moWin32_OperatingSystem["OSArchitecture"].ToString() + ")";
                        }
                    }

How to get SerialNumber
SerialNumber can be found in “Win32_SystemEnclosure” class.

                    ManagementPath mpWin32_SystemEnclosure = new ManagementPath("Win32_SystemEnclosure");
                    ManagementClass mcWin32_SystemEnclosure = new ManagementClass(ManagementScope1, mpWin32_SystemEnclosure, objectGetOptions);
                    string sServiceTag_SerialNo="";
                    foreach (ManagementObject moWin32_SystemEnclosure in mcWin32_SystemEnclosure.GetInstances())
                    {
                        sServiceTag_SerialNo = moWin32_SystemEnclosure["SerialNumber"].ToString();
                    }

How to get Processor
Processor can be found in “Win32_Processor” class.

                    ManagementPath mpWin32_Processor = new ManagementPath("Win32_Processor");
                    ManagementClass mcWin32_Processor = new ManagementClass(ManagementScope1, mpWin32_Processor, objectGetOptions);
                    string sProcessor ="";
                    foreach (ManagementObject moWin32_Processor in mcWin32_Processor.GetInstances())
                    {
                        sProcessor = moWin32_Processor["Name"].ToString();
                    }

How to get MAC Address
MAC Address can be found in “Win32_NetworkAdapterConfiguration” class.

                    ManagementPath mpWin32_NetworkAdapterConfiguration = new ManagementPath("Win32_NetworkAdapterConfiguration");
                    ManagementClass mcWin32_NetworkAdapterConfiguration = new ManagementClass(ManagementScope1, mpWin32_NetworkAdapterConfiguration, objectGetOptions);
                    string sMACAddress = "";
                    foreach (ManagementObject moWin32_NetworkAdapterConfiguration in mcWin32_NetworkAdapterConfiguration.GetInstances())
                    {                        
                         if ((bool)moWin32_NetworkAdapterConfiguration["IPEnabled"] == true)
                           {
                                sMACAddress = moWin32_NetworkAdapterConfiguration["MACAddress"].ToString();
                           }                        
                    }

How to get DesktopMonitor.
DesktopMonitor can be found in “Win32_DesktopMonitor” class.

                    ManagementPath mpWin32_DesktopMonitor = new ManagementPath("Win32_DesktopMonitor");
                    ManagementClass mcWin32_DesktopMonitor = new ManagementClass(ManagementScope1, mpWin32_DesktopMonitor, objectGetOptions);
                    string sTFT = "";
                    foreach (ManagementObject moWin32_DesktopMonitor in mcWin32_DesktopMonitor.GetInstances())
                    {
                        if (moWin32_DesktopMonitor["PNPDeviceID"] != null)
                        {
                            sTFT = sTFT + moWin32_DesktopMonitor["Name"].ToString() + ", " + moWin32_DesktopMonitor["PNPDeviceID"].ToString();
                        }
                    }                   

How to get Keyboard.
Keyboard can be found in “Win32_Keyboard” class.

                    ManagementPath mpWin32_Keyboard = new ManagementPath("Win32_Keyboard");
                    ManagementClass mcWin32_Keyboard = new ManagementClass(ManagementScope1, mpWin32_Keyboard, objectGetOptions);
                    string sKeyboard ="";
                    foreach (ManagementObject moWin32_Keyboard in mcWin32_Keyboard.GetInstances())
                    {
                        sKeyboard = moWin32_Keyboard["PNPDeviceID"].ToString();
                        break;
                    }

How to get Mouse.
Mouse can be found in “Win32_PointingDevice” class.

                    ManagementPath mpWin32_Mouse = new ManagementPath("Win32_PointingDevice");
                    ManagementClass mcWin32_Mouse = new ManagementClass(ManagementScope1, mpWin32_Mouse, objectGetOptions);
                    string sMouse = "";
                    foreach (ManagementObject moWin32_Mouse in mcWin32_Mouse.GetInstances())
                    {
                        sMouse = moWin32_Mouse["PNPDeviceID"].ToString();
                        break;
                    }

How to get Dual Card.
Dual Card can be found in “Win32_DisplayConfiguration” class.

                    string wqDualCard = "SELECT * FROM Win32_DisplayConfiguration";
                    ManagementObjectSearcher searcherDualCard = new ManagementObjectSearcher(ManagementScope1.Path.ToString(), wqDualCard);
                    ManagementObjectCollection mocDualCard = searcherDualCard.Get();
                    string DualCard ="";
                    foreach (ManagementObject moDualCard in mocDualCard)
                    {
                        foreach (PropertyData pdDualCard in moDualCard.Properties)
                        {
                            if (pdDualCard.Name == "Description")
                            {
                                DualCard = DualCard + pdDualCard.Value.ToString();
                            }
                        }
                    }

How to get Software Details.
Software Details can be found in “Win32_Product” class.

                string wqSoftwareDetails = string.Format("SELECT * FROM Win32_Product");
                ManagementObjectSearcher mosSoftwareDetails = new ManagementObjectSearcher(ManagementScope1.Path.ToString(), wqSoftwareDetails);
                foreach (ManagementObject moSoftwareDetails in mosSoftwareDetails.Get())
                {
                    string SoftwareName = string.Empty;
                    string Version = string.Empty;
                    string InstallationDate = string.Empty;
                    if (moSoftwareDetails["Name"] != null)
                    {
                        SoftwareName = moSoftwareDetails["Name"].ToString();
                    }
                    if (moSoftwareDetails["Version"] != null)
                    {
                        Version = moSoftwareDetails["Version"].ToString();
                    }
                    if (moSoftwareDetails["InstallDate"] != null)
                    {
                        InstallationDate = moSoftwareDetails["InstallDate"].ToString();
                    }                    
                }

How to get Hard Disk Details.
Hard Disk Details can be found in “Win32_LogicalDisk” class.

                ManagementObjectSearcher mosHardDiskDetails = new ManagementObjectSearcher(ManagementScope1.Path.ToString(), wqHardDiskDetails);
                foreach (ManagementObject moHardDiskDetails in mosHardDiskDetails.Get())
                {
                    string HardDiskName = string.Empty;
                    Int64 Size = 0;
                    Int64 FreeSpace = 0;
                    string InstallationDate = string.Empty;
                    if (moHardDiskDetails["Name"] != null)
                    {
                        HardDiskName = moHardDiskDetails["Name"].ToString();
                    }
                    if (moHardDiskDetails["Size"] != null)
                    {
                        Size = Convert.ToInt64(moHardDiskDetails["Size"]);
                    }
                    if (moHardDiskDetails["FreeSpace"] != null)
                    {
                        FreeSpace = Convert.ToInt64(moHardDiskDetails["FreeSpace"]);
                    }
                    if (moHardDiskDetails["InstallDate"] != null)
                    {
                        InstallationDate = moHardDiskDetails["InstallDate"].ToString();
                    }                   
                }