C#获得硬件和操作系统各项信息

【震撼发布】百木破解-IP代理软件 V1.0.0.0
http://www.bmpj.net/thread-1743-1-1.html

 

using System;
using System.Collections.Generic;
using System.Text;
using System.Management;

namespace MonitorSoftware
{
    internal class Computer
    {
        internal static string CPUName
        {
            get
            {
                string cpuinfo = "unknow";
                ManagementClass mc = new ManagementClass("win32_processor");
                ManagementObjectCollection moc = mc.GetInstances();

                foreach (ManagementObject mo in moc)
                {
                    cpuinfo = mo["Name"].ToString();
                }
                moc.Dispose();
                return cpuinfo;
            }
        }
  
  private static string CPUSN
        {
            get
            {
                string sn = "";//cpu序列号
                ManagementClass cimobject = new ManagementClass("Win32_Processor");
                ManagementObjectCollection moc = cimobject.GetInstances();
                foreach (ManagementObject mo in moc)
                {
                    sn = mo.Properties["ProcessorId"].Value.ToString();
                }
                return sn;
            }
        }
  
    private static string HardDiskID
        {
            get
            {
                string hdid="";
                ManagementClass cimobject1 = new ManagementClass("Win32_DiskDrive");
                ManagementObjectCollection moc1 = cimobject1.GetInstances();
                foreach (ManagementObject mo in moc1)
                {
                    hdid = mo.Properties["Model"].Value.ToString ();
                }

                return hdid;
            }
        }

        internal static string MAC
        {
            get
            {
                string mac = "unknow";
                ManagementClass mAdapter = new ManagementClass("Win32_NetworkAdapterConfiguration");
                ManagementObjectCollection moc = mAdapter.GetInstances();
                foreach (ManagementBaseObject mo in moc)
                {
                    if ((bool)mo["IpEnabled"] == true)
                    {
                        mac = mo["MacAddress"].ToString();
                    }
                }
                moc.Dispose();
                return mac;
            }
          
       }

        internal static string MemorySize
        {
            get
            {
                ManagementClass mc = new ManagementClass("Win32_OperatingSystem");
                ManagementObjectCollection moc = mc.GetInstances();
                double sizeAll = 0.0;
                foreach (ManagementObject mo in moc)
                {
                    if (mo.Properties["TotalVisibleMemorySize"].Value != null)
                    {
                        sizeAll += Convert.ToDouble(mo.Properties["TotalVisibleMemorySize"].Value.ToString());
                    }
                }
                //sizeAll /= 1000000;
                moc.Dispose();
                return sizeAll.ToString("0.###");
            }

        }

        internal static string[] IPAddress
        {
            get
            {
                string hostname = System.Net.Dns.GetHostName();
                System.Net.IPHostEntry ipEntry = System.Net.Dns.GetHostEntry(hostname);
                string[] ips = new string[ipEntry.AddressList.Length];
                for (int i = 0; i < ipEntry.AddressList.Length; i++)
                {
                    ips[i] = ipEntry.AddressList[i].ToString();
                }
                return ips;
            }
        }

        internal static string OSType
        {
            get
            {
                return System.Environment.OSVersion.VersionString;
            }
          
        }

    }
}

 

 

你可能感兴趣的:(C#获得硬件和操作系统各项信息)