在 Windows 7 中使用 WMI/powershell 获取屏幕分辨率 [英] Get Screen resolution using WMI/powershell in Windows 7

查看:31
本文介绍了在 Windows 7 中使用 WMI/powershell 获取屏幕分辨率的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用以下脚本通过 WMI 在 Windows 中获取屏幕分辨率.该脚本在计算机处于横向模式时运行良好,但在纵向模式下返回不正确的值.在 XP 中正常工作,在 Vista 中没有尝试.谁能确认这是 Windows 7 WMI 中的错误.

I am using the following script to get screen resolution in Windows using WMI. The script works fine when the computer is in landscape mode but returns incorrect values when in portrait mode. Works properly in XP and did not try in Vista. Can anyone confirm this is bug in Windows 7 WMI.

strComputer = "." 
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2") 
Set colItems = objWMIService.ExecQuery( _
    "SELECT * FROM Win32_DesktopMonitor",,48) 
For Each objItem in colItems 
    Wscript.Echo "-----------------------------------"
    Wscript.Echo "Win32_DesktopMonitor instance"
    Wscript.Echo "-----------------------------------"
    Wscript.Echo "ScreenHeight: " & objItem.ScreenHeight
    Wscript.Echo "ScreenWidth: " & objItem.ScreenWidth
Next

推荐答案

为了记录,PowerShell 代码是:

For the record, the PowerShell code is:

Get-WmiObject -Class Win32_DesktopMonitor | Select-Object ScreenWidth,ScreenHeight

我在横向或纵向模式下获得相同的值.

I get the same values in Landscape or in Portrait mode.

更新:

在多显示器环境中,您可以通过以下方式获取所有显示器的信息:

In a multi monitor environment you can get the info for all monitors with:

PS> Add-Type -AssemblyName System.Windows.Forms
PS> [System.Windows.Forms.Screen]::AllScreens


BitsPerPixel : 32
Bounds       : {X=0,Y=0,Width=1280,Height=800}
DeviceName   : \\.\DISPLAY1
Primary      : True
WorkingArea  : {X=0,Y=0,Width=1280,Height=770}

BitsPerPixel : 32
Bounds       : {X=1280,Y=0,Width=1920,Height=1200}
DeviceName   : \\.\DISPLAY2
Primary      : False
WorkingArea  : {X=1280,Y=0,Width=1920,Height=1170}

这篇关于在 Windows 7 中使用 WMI/powershell 获取屏幕分辨率的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆