use*_*693 16 powershell wmi windows-7
我使用以下脚本在Windows中使用WMI获取屏幕分辨率.当计算机处于横向模式时,脚本可以正常工作,但在纵向模式下,脚本返回不正确的值.在XP中正常工作,并没有在Vista中尝试.任何人都可以确认这是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
Run Code Online (Sandbox Code Playgroud)
Sha*_*evy 33
对于记录,PowerShell代码是:
Get-WmiObject -Class Win32_DesktopMonitor | Select-Object ScreenWidth,ScreenHeight
Run Code Online (Sandbox Code Playgroud)
我在横向或纵向模式下获得相同的值.
更新:
在多监视器环境中,您可以使用以下命令获取所有监视器的信息:
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}
Run Code Online (Sandbox Code Playgroud)
Tre*_*van 11
您可以从Win32_VideoController
WMI类中获取此信息.该VideoModeDescription
属性包括屏幕分辨率和颜色深度.
(Get-WmiObject -Class Win32_VideoController).VideoModeDescription;
Run Code Online (Sandbox Code Playgroud)
1600 x 900 x 4294967296 colors
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
56716 次 |
最近记录: |