在使用WMI对象前,先要添加对System.Management的引用,然后就可以调用WMI对象。

我们使用的WMI对象是:Win32_DesktopMonitor

对象参考:http://msdn.microsoft.com/zh-cn/library/Aa394122

代码:

        static void Main(string[] args) {

using (ManagementClass mc = new ManagementClass("Win32_DesktopMonitor")) {
using (ManagementObjectCollection moc = mc.GetInstances()) {

int PixelsPerXLogicalInch = 0; // dpi for x
int PixelsPerYLogicalInch = 0; // dpi for y

foreach (ManagementObject each in moc) {
PixelsPerXLogicalInch = int.Parse((each.Properties["PixelsPerXLogicalInch"].Value.ToString()));
PixelsPerYLogicalInch = int.Parse((each.Properties["PixelsPerYLogicalInch"].Value.ToString()));
}

Console.WriteLine("PixelsPerXLogicalInch:" + PixelsPerXLogicalInch.ToString());
Console.WriteLine("PixelsPerYLogicalInch:" + PixelsPerYLogicalInch.ToString());
Console.Read();
}

}
}

以上代码在WIN7的环境下测试通过。

相关文章:

  • 2022-01-15
  • 2022-12-23
  • 2022-03-06
  • 2021-09-05
  • 2022-12-23
  • 2022-12-23
  • 2021-07-30
  • 2022-12-23
猜你喜欢
  • 2021-10-18
  • 2021-05-30
  • 2021-11-21
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案