1、Windows Management Instrumentation(WMI)提供了获取信息的方法,在C#中可用通过System.Management命名空间中的类访问。比如获取CPU ID的方法:

stringGetCpuID()

{try{stringid="";

ManagementClass mc=newManagementClass("Win32_Processor");

ManagementObjectCollection moc=mc.GetInstances();foreach(ManagementObject moinmoc)

{

id=mo.Properties["ProcessorId"].Value.ToString();

}returnid;

}catch{return"unknow";

}

}

2、那么像“Win32_Processor”、“ProcessorId”一类的字符串该如何写?这里有详细说明:

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

比如主板信息的Win32_BaseBoard类:

classWin32_BaseBoard : CIM_Card

{stringCaption;stringConfigOptions[];stringCreationClassName;

real32 Depth;stringDescription;

real32 Height;

boolean HostingBoard;

boolean HotSwappable;

datetime InstallDate;stringManufacturer;stringModel;stringName;stringOtherIdentifyingInfo;stringPartNumber;

boolean PoweredOn;stringProduct;

boolean Removable;

boolean Replaceable;stringRequirementsDescription;

boolean RequiresDaughterBoard;stringSerialNumber;stringSKU;stringSlotLayout;

boolean SpecialRequirements;stringStatus;stringTag;stringVersion;

real32 Weight;

real32 Width;

};

如果我们想知道主板的SerialNumber,参照Win32_BaseBoard类的红色文字,我们就可以写出如下代码:

stringGetMotherBoardSerialNumber()

{try{stringsn="";

ManagementClass mc=newManagementClass("Win32_BaseBoard");

ManagementObjectCollection moc=mc.GetInstances();foreach(ManagementObject moinmoc)

{

sn=mo.Properties["SerialNumber"].Value.ToString();

}returnsn;

}catch{return"unknow";

}

}

3、例子:

注释部分是在测试机器上得到的值。

privatevoidCpuInfo()

{try{

ManagementClass mc=newManagementClass("Win32_Processor");

ManagementObjectCollection moc=mc.GetInstances();foreach(ManagementObject moinmoc)

{

UInt16 AddressWidth=(UInt16)(mo.Properties["AddressWidth"].Value);//32UInt16 DataWidth=(UInt16)(mo.Properties["DataWidth"].Value);//32UInt32 CurrentClockSpeed=(UInt32)(mo.Properties["CurrentClockSpeed"].Value);//2810UInt32 MaxClockSpeed=(UInt32)(mo.Properties["MaxClockSpeed"].Value);//2810UInt32 ExtClock=(UInt32)(mo.Properties["ExtClock"].Value);//200stringManufacturer=mo.Properties["Manufacturer"].Value.ToString();//GenuineIntelstringCaption=mo.Properties["Caption"].Value.ToString();//x86 Family 15 Model 4 Stepping 7stringName=mo.Properties["Name"].Value.ToString();//Intel(R) Pentium(R) D CPU 2.80GHzstringSocketDesignation=mo.Properties["SocketDesignation"].Value.ToString();//socket775}

}catch(Exception ex)

{

Console.WriteLine("unknow");

}

}

privatevoidGetMotherBoardInfo()

{try{

ManagementClass mc=newManagementClass("Win32_BaseBoard");

ManagementObjectCollection moc=mc.GetInstances();foreach(ManagementObject moinmoc)

{stringManufacturer=mo.Properties["Manufacturer"].Value.ToString();//ASUSTeK Computer INC.stringName=mo.Properties["Name"].Value.ToString();//底板stringProduct=mo.Properties["Product"].Value.ToString();//P5PL2stringSlotLayout=mo.Properties["SlotLayout"].Value.ToString();//在测试机器上没有得到该信息stringVersion=mo.Properties["Version"].Value.ToString();//Rev 1.xx}

}catch(Exception ex)

{

Console.WriteLine("unknow");

}

}

privatevoidDiskInfo()

{try{

ManagementClass mc=newManagementClass("Win32_DiskDrive");

ManagementObjectCollection moc=mc.GetInstances();foreach(ManagementObject moinmoc)

{stringInterfaceType=mo.Properties["InterfaceType"].Value.ToString();//IDEstringModel=mo.Properties["Model"].Value.ToString();//MAXTOR 6L080J4stringName=mo.Properties["Name"].Value.ToString();//\\.\PHYSICALDRIVE0UInt32 Partitions=(UInt32)(mo.Properties["Partitions"].Value);//1UInt64 Size=(UInt64)(mo.Properties["Size"].Value);//80048424960UInt64 TotalCylinders=(UInt64)(mo.Properties["TotalCylinders"].Value);//9732UInt32 TotalHeads=(UInt32)(mo.Properties["TotalHeads"].Value);//255UInt64 TotalSectors=(UInt64)(mo.Properties["TotalSectors"].Value);//156344580UInt64 TotalTracks=(UInt64)(mo.Properties["TotalTracks"].Value);//2481660}

}catch(Exception ex)

{

Console.WriteLine(ex.Message);

}

}

4、用WMI获得信息也存在一个小问题,就是比较慢,性能不好。如果对性能有要求,就要通过平台调用的方式调用Win32相关函数。比如通过下面函数可得到物理内存大小等信息:

[DllImport("kernel32")]

private static extern void GlobalMemoryStatus(ref MemoryInfo memInfo);

5、其他参考:

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

来源:https://www.cnblogs.com/h2appy/archive/2008/09/03/1282792.html

计算机硬盘哪里找到相关信息,获取计算机的信息(IP地址、MAC地址、CUP序列号、硬盘序列号、主板信息等等)...相关推荐

  1. 批处理获取计算机域名,用批处理获取局域网中电脑ip和mac地址表

    用批处理获取局域网中电脑ip和mac地址表 为了避免IP地址抵触和体系安全,局域网中电脑的IP地址和MAC地址对照表是要常常备份的.除了能够运用软件处理外,用细巧专心的批处理也是一个不错的挑选.用记事 ...

  2. Java获取局域网中所有ip和Mac地址

    Java获取局域网中所有ip和Mac地址 定义一个Util public class IpAndMacUtil {/*** 获取本机Mac地址* @param ia* @return* @throws ...

  3. C#获取路由器外网IP,MAC地址

    C#实现的获取路由器MAC地址,路由器外网地址.对于要获取路由器MAC地址,一定需要知道路由器web管理系统的用户名和密码.至于获取路由器的外网IP地址,可以不需要知道路由器web管理系统的用户名和密 ...

  4. python Scapy获取局域网内的IP和mac地址

    ''' python3 安装scapy-python3 注:linux,可能需要以root登陆,避免出现permission error Scapy还包含内建函数arping(),该函数实现的功能和以 ...

  5. python获取mac、计算机id_python 获取本机IP、mac地址、计算机名的简单示例

    这篇文章主要为大家详细介绍了python 获取本机IP.mac地址.计算机名的简单示例,具有一定的参考价值,可以用来参考一下. 对python获取本机IP.mac地址.计算机名感兴趣的小伙伴,下面一起 ...

  6. 没有计算机网络地址怎么办,教大家电脑没有ip地址mac地址怎么办

    近日有关于电脑没有ip地址mac地址怎么办的问题受到了很多网友们的关注,大多数网友都想要知道电脑没有ip地址mac地址怎么办的具体情况,那么关于到电脑没有ip地址mac地址怎么办的相关信息,小编也是在 ...

  7. mac中如何查看工作组计算机名,如何查询局域网内全部电脑IP和mac地址

    你知道局域网内全部电脑IP和mac地址吗,那么该如何查询局域网内全部电脑IP和mac地址呢下面是学习啦小编收集整理的如何查询局域网内全部电脑IP和mac地址,希望对大家有帮助~~ 查询局域网内全部电脑 ...

  8. C语言获取硬件信息(CPU序列号,硬盘序列号,网卡IP、MAC地址、是否插入网线)

    目录 一.前言 二.代码实现 2.1 获取CPU序列号 2.2 获取硬盘序列号 2.3 获取网卡信息 附:源代码下载 一.前言   本文主要介绍Linux和Windows下使用C语言获取各种硬件信息, ...

  9. 怎么查询局域网内全部电脑IP和mac地址等信息?

    在局域网内查询在线主机的IP一般比较简单,但局域网内全部电脑的IP怎么才能够查到呢?查询到IP后我还要知道对方的一些详细信息(如MAC地址.电脑名称等)该怎么查询呢???或者用命令 :arp -a   ...

  10. java自动获取ip_java自动获取电脑ip和MAC地址

    java自动获取电脑ip和MAC地址 利用getLocalHost获得计算机名称和ip getByInetAddress可以确定一个IP地址属于哪一个网络接口,这个IP地址通过命令行参数传入 用get ...

最新文章

  1. listen()与accept()函数的区别
  2. [转]ASP.Net篇之Session与Cookie
  3. EntityFramework Core 3.0 Preview
  4. 根据中序、前序遍历重建二叉树
  5. Python打包 pyinstaller
  6. 微信成为开发者_如何成为开发者
  7. 程序员养生(01) -- 心态
  8. 英伟达发布全球最大GPU:性能提升10倍,售价250万
  9. 只需两步快速获取微信小程序源码
  10. 12.1 动态内存与智能指针(2)
  11. Linux学习技巧分享
  12. 【pandas】column变index,dataframe转置
  13. java计算机毕业设计网上书店管理系统源码+系统+数据库+lw文档+mybatis+运行部署
  14. 行测中数量关系的练习题集(07-29)【2】
  15. 《先知·逸乐》| 《先知·自由》
  16. 如何下载网页上的视频
  17. 题解:女神间的 BOYI # 博弈论 # surreal number
  18. R3 Corda:一个为金融服务设计的分布式账本系统
  19. Moodle 2的新增的功能
  20. 项目管理协会(PMI)人才三角

热门文章

  1. Quartus中Tools->Netlist Viewers->RTL Viewer
  2. linux文档采集前五行,Linux 学习-Shell筛选top前五行信息
  3. Java多线程知识整理
  4. pandas重置索引的几种方法探究
  5. Win8Metro(C#)数字图像处理--2.7图像伪彩色
  6. OpenGL杂七杂八
  7. js判断变量类型是否为字符串,不符合条件则赋值为‘无’
  8. 昆特牌Online——客户端用到的一些技术
  9. HDU 1754 I Hate It(线段树版)
  10. 编程之美——3.1字符串移位包含问题