Get the MAC,CPU number of the machine, the CPU number, the hard plate and the memory size

Source: Internet
Author: User

/// <summary>          ///get MAC address of native/// </summary>          /// <returns></returns>           Public Static stringgetmacstring () {ManagementClass madapter=NewManagementClass ("Win32_NetworkAdapterConfiguration"); Managementobjectcollection Mo=madapter.getinstances (); foreach(Managementbaseobject minchmo) {                if((BOOL) m["ipenabled"] ==true)                {                    returnm["MacAddress"].                ToString (); }} mo.            Dispose (); return NULL; //ManagementClass mc = new ManagementClass ("Win32_NetworkAdapterConfiguration"); //managementobjectcollection MOC = mc.            GetInstances (); //foreach (ManagementObject mo in MOC)//{            //    //If no IP settings are enabled for network devices, skip//if (! ( BOOL) mo["ipenabled"])//continue; //    //Get Properties//String caption = mo["caption"].              ToString (); //name//string[] addresses = (string[]) mo["IPAddress"]; //IP Address//string[] subnets = (string[]) mo["IPSubnet"]; //Subnet Mask//string[] gateways = (string[]) mo["DefaultIPGateway"]; //Gateway//string[] dnses = (string[]) mo["DNSServerSearchOrder"]; //DNS//Managementbaseobject Newip; //    //modify IP and subnet masks//NEWIP = mo.            Getmethodparameters ("EnableStatic"); //newip["IPAddress"] = new string[] {"192.168.2.51"}; //newip["SubnetMask"] = new string[] {"255.255.255.0"};//Modify IP at the same time, you need to fill in the subnet mask//mo.            InvokeMethod ("EnableStatic", NEWIP, NULL); //    //Set the gateway address//NEWIP = mo.            Getmethodparameters ("SetGateways"); //newip["DefaultIPGateway"] = new string[] {"192.168.2.1"}; //mo.            InvokeMethod ("SetGateways", NEWIP, NULL); //    //set up DNS//NEWIP = mo.            Getmethodparameters ("SetDNSServerSearchOrder"); //newip["DNSServerSearchOrder"] = new string[] {"192.168.1.10"}; //mo. InvokeMethod ("SetDNSServerSearchOrder", NEWIP, null);        }        /// <summary>          ///get the number of CPUs/// </summary>          /// <returns></returns>          Public Static intGetcpucount () {Try            {                using(ManagementClass mcpu =NewManagementClass ("Win32_Processor") {managementobjectcollection CPUs=mcpu.getinstances (); returnCPUs.                Count; }            }            Catch            {            }            return-1; }        /// <summary>          ///how often to get the CPU the use of a string type array is mainly due to the multi-core of the CPU/// </summary>          /// <returns></returns>           Public Static string[] Getcpumhz () {ManagementClass mc=NewManagementClass ("Win32_Processor"); Managementobjectcollection CPUs=MC.            GetInstances (); string[] MHz =New string[CPUs.            Count]; intc =0; ManagementObjectSearcher Mysearch=NewManagementObjectSearcher ("SELECT * from Win32_Processor"); foreach(ManagementObject moinchMysearch.get ()) {Mhz[c]= mo. properties["CurrentClockSpeed"].                Value.tostring (); C++; } MC.            Dispose ();            Mysearch.dispose (); returnmHz; }        /// <summary>          ///get the size of the hard disk/// </summary>          /// <returns></returns>           Public Static stringGetsizeofdisk () {ManagementClass mc=NewManagementClass ("win32_diskdrive"); Managementobjectcollection MoJ=MC.            GetInstances (); foreach(ManagementObject minchMoJ) {                returnm.properties["Size"].            Value.tostring (); }            return "-1"; }        /// <summary>          ///get the size of the memory/// </summary>          /// <returns></returns>           Public Static stringGetsizeofmemery () {ManagementClass mc=NewManagementClass ("Win32_OperatingSystem"); Managementobjectcollection MOC=MC.            GetInstances (); DoubleSizeall =0.0; foreach(ManagementObject minchMOC) {                if(m.properties["totalvisiblememorysize"]. Value! =NULL) {Sizeall+ = Convert.todouble (m.properties["totalvisiblememorysize"].                Value.tostring ()); }} MC=NULL; MoC.            Dispose (); returnsizeall.tostring (); }

Get the MAC,CPU number of the machine, the CPU number, the hard plate and the memory size

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.