日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

获取计算机的信息(IP地址、MAC地址、CUP序列号、硬盘序列号、主板信息等等)...

發(fā)布時間:2024/4/15 编程问答 34 豆豆
生活随笔 收集整理的這篇文章主要介紹了 获取计算机的信息(IP地址、MAC地址、CUP序列号、硬盘序列号、主板信息等等)... 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

1、Windows Management Instrumentation(WMI)提供了獲取信息的方法,在C#中可用通過System.Management命名空間中的類訪問。比如獲取CPU ID的方法:

?

????????string?GetCpuID()
????????{
????????????
try
????????????{
????????????????
string?id?=?"";
????????????????ManagementClass?mc?
=?new?ManagementClass("Win32_Processor");
????????????????ManagementObjectCollection?moc?
=?mc.GetInstances();
????????????????
foreach?(ManagementObject?mo?in?moc)
????????????????{
????????????????????id?
=?mo.Properties["ProcessorId"].Value.ToString();
????????????????}
????????????????
return?id;
????????????}
????????????
catch
????????????{
????????????????
return?"unknow";
????????????}
????????}

?

?

?

?

2、那么像“Win32_Processor”、“ProcessorId”一類的字符串該如何寫?這里有詳細說明:

?

http://msdn.microsoft.com/en-us/library/aa394084(VS.85).aspx

??? 比如主板信息的Win32_BaseBoard類:

?

class?Win32_BaseBoard?:?CIM_Card
{
??
string?Caption;
??
string?ConfigOptions[];
??
string?CreationClassName;
??real32?Depth;
??
string?Description;
??real32?Height;
??boolean?HostingBoard;
??boolean?HotSwappable;
??datetime?InstallDate;
??
string?Manufacturer;
??
string?Model;
??
string?Name;
??
string?OtherIdentifyingInfo;
??
string?PartNumber;
??boolean?PoweredOn;
??
string?Product;
??boolean?Removable;
??boolean?Replaceable;
??
string?RequirementsDescription;
??boolean?RequiresDaughterBoard;
??
string?SerialNumber;
??
string?SKU;
??
string?SlotLayout;
??boolean?SpecialRequirements;
??
string?Status;
??
string?Tag;
??
string?Version;
??real32?Weight;
??real32?Width;
};

?

?

?

如果我們想知道主板的SerialNumber,參照Win32_BaseBoard類的紅色文字,我們就可以寫出如下代碼:


????????string?GetMotherBoardSerialNumber()
????????{
????????????
try
????????????{
????????????????
string sn =?"";
????????????????ManagementClass?mc?
=?new?ManagementClass("Win32_BaseBoard");
????????????????ManagementObjectCollection?moc?
=?mc.GetInstances();
????????????????
foreach?(ManagementObject?mo?in?moc)
????????????????{
??????????????????? sn
=?mo.Properties["SerialNumber"].Value.ToString();
????????????????}
????????????????
return sn;
????????????}
????????????
catch
????????????{
????????????????
return?"unknow";
????????????}
????????}

?

?


3、例子:

??? 注釋部分是在測試機器上得到的值。


????????private?void?CpuInfo()
????????{
????????????
try
????????????{
????????????????ManagementClass?mc?
=?new?ManagementClass("Win32_Processor");
????????????????ManagementObjectCollection?moc?
=?mc.GetInstances();
????????????????
foreach?(ManagementObject?mo?in?moc)
????????????????{
????????????????????UInt16?AddressWidth?
=?(UInt16)(mo.Properties["AddressWidth"].Value);//32
????????????????????UInt16?DataWidth?=?(UInt16)(mo.Properties["DataWidth"].Value);//32
????????????????????UInt32?CurrentClockSpeed?=?(UInt32)(mo.Properties["CurrentClockSpeed"].Value);//2810
????????????????????UInt32?MaxClockSpeed?=?(UInt32)(mo.Properties["MaxClockSpeed"].Value);//2810????????????????????
????????????????????UInt32?ExtClock?=?(UInt32)(mo.Properties["ExtClock"].Value);//200
????????????????????string?Manufacturer?=?mo.Properties["Manufacturer"].Value.ToString();//GenuineIntel
????????????????????string?Caption?=?mo.Properties["Caption"].Value.ToString();//x86?Family?15?Model?4?Stepping?7
????????????????????string?Name?=?mo.Properties["Name"].Value.ToString();//Intel(R)?Pentium(R)?D?CPU?2.80GHz???????
????????????????????string?SocketDesignation?=?mo.Properties["SocketDesignation"].Value.ToString();//socket775
????????????????}
????????????}
????????????
catch?(Exception?ex)
????????????{
????????????????Console.WriteLine(
"unknow");
????????????}
????????}

?

????????private?void?GetMotherBoardInfo()
????????{
????????????
try
????????????{
????????????????ManagementClass?mc?
=?new?ManagementClass("Win32_BaseBoard");
????????????????ManagementObjectCollection?moc?
=?mc.GetInstances();
????????????????
foreach?(ManagementObject?mo?in?moc)
????????????????{
????????????????????
string?Manufacturer?=?mo.Properties["Manufacturer"].Value.ToString();//ASUSTeK?Computer?INC.
????????????????????string?Name?=?mo.Properties["Name"].Value.ToString();//底板
????????????????????string?Product?=?mo.Properties["Product"].Value.ToString();//P5PL2
????????????????????string?SlotLayout?=?mo.Properties["SlotLayout"].Value.ToString();//在測試機器上沒有得到該信息
????????????????????string?Version?=?mo.Properties["Version"].Value.ToString();//Rev?1.xx
????????????????}
????????????}
????????????
catch(Exception?ex)
????????????{
????????????????Console.WriteLine(
"unknow");
????????????}
????????}

?

????????private?void?DiskInfo()
????????{
????????????
try
????????????{
????????????????ManagementClass?mc?
=?new?ManagementClass("Win32_DiskDrive");
????????????????ManagementObjectCollection?moc?
=?mc.GetInstances();
????????????????
foreach?(ManagementObject?mo?in?moc)
????????????????{
????????????????????
string?InterfaceType?=?mo.Properties["InterfaceType"].Value.ToString();//IDE
????????????????????string?Model?=?mo.Properties["Model"].Value.ToString();//MAXTOR?6L080J4
????????????????????string?Name?=?mo.Properties["Name"].Value.ToString();//\\.\PHYSICALDRIVE0
????????????????????UInt32?Partitions?=?(UInt32)(mo.Properties["Partitions"].Value);//1
????????????????????UInt64?Size?=?(UInt64)(mo.Properties["Size"].Value);//80048424960
????????????????????UInt64?TotalCylinders?=?(UInt64)(mo.Properties["TotalCylinders"].Value);//9732
????????????????????UInt32?TotalHeads?=?(UInt32)(mo.Properties["TotalHeads"].Value);//255
????????????????????UInt64?TotalSectors?=?(UInt64)(mo.Properties["TotalSectors"].Value);//156344580
????????????????????UInt64?TotalTracks?=?(UInt64)(mo.Properties["TotalTracks"].Value);//2481660
????????????????}
????????????}
????????????
catch?(Exception?ex)
????????????{
????????????????Console.WriteLine(ex.Message);
????????????}
????????}

?

?

4、用WMI獲得信息也存在一個小問題,就是比較慢,性能不好。如果對性能有要求,就要通過平臺調(diào)用的方式調(diào)用Win32相關(guān)函數(shù)。比如通過下面函數(shù)可得到物理內(nèi)存大小等信息:

?

???????? [DllImport("kernel32")]
??????? private static extern void GlobalMemoryStatus(ref MemoryInfo memInfo);

?

5、其他參考:

http://www.cnblogs.com/draeag/archive/2007/06/21/791992.html?

?


?

轉(zhuǎn)載于:https://www.cnblogs.com/h2appy/archive/2008/09/03/1282792.html

超強干貨來襲 云風(fēng)專訪:近40年碼齡,通宵達旦的技術(shù)人生

總結(jié)

以上是生活随笔為你收集整理的获取计算机的信息(IP地址、MAC地址、CUP序列号、硬盘序列号、主板信息等等)...的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。