c# - 使用WMI(Windows Management Instrument)取得硬件信息
2012-06-30 15:48
381 查看
这个例子只是取得一台机器的内存,更多的Win32 对象在下面,您可以用同样的方式取得这些信息。 http://msdn.microsoft.com/en-us/library/windows/desktop/aa394197
using System.Management;
using System.Management;
public static long GetTotalMemory(string p_MachineName, string p_Domain = null, string p_Username = null, string p_Password = null) { try { long memSize = 0; ManagementScope connectionScope = new ManagementScope(); ConnectionOptions options = new ConnectionOptions(); options.Impersonation = ImpersonationLevel.Impersonate; if (p_Domain != null && p_Username != null && p_Password != null) { options.Username = p_Domain + @"\" + p_Username; options.Password = p_Password; } else { options.Authentication = AuthenticationLevel.Default; } connectionScope.Options = options; connectionScope.Path = new ManagementPath(@"\\" + p_MachineName + @"\root\cimv2"); connectionScope.Connect(); SelectQuery msQuery = new SelectQuery("SELECT * FROM Win32_MemoryDevice"); ManagementObjectSearcher searchProcedure = new ManagementObjectSearcher(connectionScope, msQuery); foreach (ManagementObject item in searchProcedure.Get()) { long startAddr = Convert.ToInt64(item["StartingAddress"].ToString()); long endAddr = Convert.ToInt64(item["EndingAddress"].ToString()); memSize += (endAddr - startAddr); } return memSize; } catch (Exception ex) { throw ex; } }
相关文章推荐
- C#中如何用Windows Management Instrumentation (WMI)得到系统信息
- windows下WMI使用C++查询用户硬件信息
- 【PERL】使用wmi获取windows硬件信息
- asp.net(C#)通过WMI无法获取磁盘卷序列号(硬件信息)的问题解决办
- 解决【Windows Management Instrumentation(WMI)信息可能损坏】
- c#使用PortableDeviceApiLib读取便携式设备(WPD:Windows Portable Devices)信息
- python使用WMI检测windows系统信息、硬盘信息、网卡信息的方法
- 在C#中使用WMI查询进程的用户信息
- 光驱无法使用——由于其配置信息(注册表中的)不完整或已损坏,Windows 无法启动这个硬件设备。 (代码 19)
- C#与WMI(二):查看远程Windows计算机的操作系统信息
- windows不能显示此连接属性。windows management instrumentation (WMI) 信息可能损坏
- 【20090903-01】C#中使用ManagementClass获取本机信息
- c#中跨线程调用windows窗体控件 .我们在做winform应用的时候,大部分情况下都会碰到使用多线程控制界面上控件信息的问题。然而我们并不能用传统方法来做这个问题,下面我将详细的介绍。
- PowerShell 2.0之使用WMI管理Windows(四)获取软硬件信息
- 使用WMI列出Windows中某个目录的用户权限(C#)
- C#获取远程计算机硬件信息实例(支持linux和windows)
- 使用SC在C#中取得windows服务的启动类型
- C#中通过wmi获取硬件的信息
- 利用Javascript通过WMI取得Windows系统信息
- python使用wmi模块获取windows下硬盘信息的方法