私は、WMI を使用して Windows の画面解像度を取得するために次のスクリプトを使用しています。このスクリプトは、コンピューターが横長モードのときは正常に動作しますが、縦長モードのときは誤った値を返します。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
ベストアンサー1
ちなみに、PowerShell コードは次のとおりです。
Get-WmiObject -Class Win32_DesktopMonitor | Select-Object ScreenWidth,ScreenHeight
横向きモードでも縦向きモードでも同じ値が得られます。
アップデート:
マルチモニター環境では、次のコマンドですべてのモニターの情報を取得できます。
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}