• Присоединяйтесь к нашей группе в телеграмм: t.me/TEHADMru

Получение информации о системе и комплектующих ПК

mexan

Администратор
Сообщения
716
Реакции
82
C#:
using System.Management;
C#:
private static string GetProcessorId()
    {
        ManagementObjectCollection instances = new ManagementClass("win32_processor").GetInstances();
        string result = string.Empty;
        using (ManagementObjectCollection.ManagementObjectEnumerator enumerator = instances.GetEnumerator())
        {
            if (enumerator.MoveNext())
            {
                result = ((ManagementObject)enumerator.Current).Properties["processorID"].Value.ToString();
            }
        }
        return result;
    }
C#:
private static string GetHDDSerialNo()
    {
        ManagementObjectCollection instances = new ManagementClass("Win32_LogicalDisk").GetInstances();
        string text = "";
        foreach (ManagementBaseObject managementBaseObject in instances)
        {
            ManagementObject managementObject = (ManagementObject)managementBaseObject;
            text += Convert.ToString(managementObject["VolumeSerialNumber"]);
        }
        return text;
    }
C#:
private static string GetMACAddress()
    {
        ManagementObjectCollection instances = new ManagementClass("Win32_NetworkAdapterConfiguration").GetInstances();
        string text = string.Empty;
        foreach (ManagementBaseObject managementBaseObject in instances)
        {
            ManagementObject managementObject = (ManagementObject)managementBaseObject;
            if (text == string.Empty && (bool)managementObject["IPEnabled"])
            {
                text = managementObject["MacAddress"].ToString();
            }
            managementObject.Dispose();
        }
        return text;
    }
C#:
private static string GetBoardMaker()
    {
        foreach (ManagementBaseObject managementBaseObject in new ManagementObjectSearcher("root\\CIMV2", "SELECT * FROM Win32_BaseBoard").Get())
        {
            ManagementObject managementObject = (ManagementObject)managementBaseObject;
            try
            {
                return managementObject.GetPropertyValue("Manufacturer").ToString();
            }
            catch
            {
            }
        }
        return "Board Maker: Unknown";
    }
C#:
private static string GetBoardProductId()
    {
        foreach (ManagementBaseObject managementBaseObject in new ManagementObjectSearcher("root\\CIMV2", "SELECT * FROM Win32_BaseBoard").Get())
        {
            ManagementObject managementObject = (ManagementObject)managementBaseObject;
            try
            {
                return managementObject.GetPropertyValue("Product").ToString();
            }
            catch
            {
            }
        }
        return "Product: Unknown";
    }
C#:
private static string GetCdRomDrive()
    {
        foreach (ManagementBaseObject managementBaseObject in new ManagementObjectSearcher("root\\CIMV2", "SELECT * FROM Win32_CDROMDrive").Get())
        {
            ManagementObject managementObject = (ManagementObject)managementBaseObject;
            try
            {
                return managementObject.GetPropertyValue("Drive").ToString();
            }
            catch
            {
            }
        }
        return "CD ROM Drive Letter: Unknown";
    }
C#:
private static string GetBIOSmaker()
    {
        foreach (ManagementBaseObject managementBaseObject in new ManagementObjectSearcher("root\\CIMV2", "SELECT * FROM Win32_BIOS").Get())
        {
            ManagementObject managementObject = (ManagementObject)managementBaseObject;
            try
            {
                return managementObject.GetPropertyValue("Manufacturer").ToString();
            }
            catch
            {
            }
        }
        return "BIOS Maker: Unknown";
    }
C#:
private static string GetBIOSserNo()
    {
        foreach (ManagementBaseObject managementBaseObject in new ManagementObjectSearcher("root\\CIMV2", "SELECT * FROM Win32_BIOS").Get())
        {
            ManagementObject managementObject = (ManagementObject)managementBaseObject;
            try
            {
                return managementObject.GetPropertyValue("SerialNumber").ToString();
            }
            catch
            {
            }
        }
        return "BIOS Serial Number: Unknown";
    }
C#:
private static string GetBIOScaption()
    {
        foreach (ManagementBaseObject managementBaseObject in new ManagementObjectSearcher("root\\CIMV2", "SELECT * FROM Win32_BIOS").Get())
        {
            ManagementObject managementObject = (ManagementObject)managementBaseObject;
            try
            {
                return managementObject.GetPropertyValue("Caption").ToString();
            }
            catch
            {
            }
        }
        return "BIOS Caption: Unknown";
    }
C#:
private static string GetAccountName()
    {
        foreach (ManagementBaseObject managementBaseObject in new ManagementObjectSearcher("root\\CIMV2", "SELECT * FROM Win32_UserAccount").Get())
        {
            ManagementObject managementObject = (ManagementObject)managementBaseObject;
            try
            {
                return managementObject.GetPropertyValue("Name").ToString();
            }
            catch
            {
            }
        }
        return "User Account Name: Unknown";
    }
C#:
private static string GetPhysicalMemory()
    {
        ManagementScope scope = new ManagementScope();
        ObjectQuery query = new ObjectQuery("SELECT Capacity FROM Win32_PhysicalMemory");
        ManagementObjectCollection managementObjectCollection = new ManagementObjectSearcher(scope, query).Get();
        long num = 0L;
        foreach (ManagementBaseObject managementBaseObject in managementObjectCollection)
        {
            long num2 = Convert.ToInt64(((ManagementObject)managementBaseObject)["Capacity"]);
            num += num2;
        }
        num = num / 1024L / 1024L;
        return num.ToString();
    }
C#:
private static string GetNoRamSlots()
    {
        int num = 0;
        ManagementScope scope = new ManagementScope();
        ObjectQuery query = new ObjectQuery("SELECT MemoryDevices FROM Win32_PhysicalMemoryArray");
        foreach (ManagementBaseObject managementBaseObject in new ManagementObjectSearcher(scope, query).Get())
        {
            num = Convert.ToInt32(((ManagementObject)managementBaseObject)["MemoryDevices"]);
        }
        return num.ToString();
    }
C#:
private static string GetCPUManufacturer()
    {
        string text = string.Empty;
        foreach (ManagementBaseObject managementBaseObject in new ManagementClass("Win32_Processor").GetInstances())
        {
            ManagementObject managementObject = (ManagementObject)managementBaseObject;
            if (text == string.Empty)
            {
                text = managementObject.Properties["Manufacturer"].Value.ToString();
            }
        }
        return text;
    }
C#:
private static string GetDefaultIPGateway()
    {
        ManagementObjectCollection instances = new ManagementClass("Win32_NetworkAdapterConfiguration").GetInstances();
        string text = string.Empty;
        foreach (ManagementBaseObject managementBaseObject in instances)
        {
            ManagementObject managementObject = (ManagementObject)managementBaseObject;
            if (text == string.Empty && (bool)managementObject["IPEnabled"])
            {
                text = managementObject["DefaultIPGateway"].ToString();
            }
            managementObject.Dispose();
        }
        return text;
    }
C#:
private static string GetOSInformation()
    {
        foreach (ManagementBaseObject managementBaseObject in new ManagementObjectSearcher("SELECT * FROM Win32_OperatingSystem").Get())
        {
            ManagementObject managementObject = (ManagementObject)managementBaseObject;
            try
            {
                return string.Concat(new string[]
                {
                    ((string)managementObject["Caption"]).Trim(),
                    ", ",
                    (string)managementObject["Version"],
                    ", ",
                    (string)managementObject["OSArchitecture"]
                });
            }
            catch
            {
            }
        }
        return "BIOS Maker: Unknown";
    }
C#:
private static string GetProcessorInformation()
    {
        ManagementObjectCollection instances = new ManagementClass("win32_processor").GetInstances();
        string result = string.Empty;
        foreach (ManagementBaseObject managementBaseObject in instances)
        {
            ManagementObject managementObject = (ManagementObject)managementBaseObject;
            string text = (string)managementObject["Name"];
            result = string.Concat(new string[]
            {
                text,
                ", ",
                (string)managementObject["Caption"],
                ", ",
                (string)managementObject["SocketDesignation"]
            });
        }
        return result;
    }
C#:
private static string GetComputerName()
    {
        ManagementObjectCollection instances = new ManagementClass("Win32_ComputerSystem").GetInstances();
        string result = string.Empty;
        foreach (ManagementBaseObject managementBaseObject in instances)
        {
            result = (string)((ManagementObject)managementBaseObject)["Name"];
        }
        return result;
    }
 
Последнее редактирование:
Верх