English 中文(简体)
视窗7使用WMI/powershell进行筛查
原标题:Get Screen resolution using WMI/powershell in Windows 7

我正在使用以下文字,在Windows使用WMI进行检测。 当计算机处于地貌时,该笔记本可操作,但当有孔隙时,其价值却不正确。 在XP中适当开展工作,在Vista没有尝试。 任何人都可以在Windows 7 WMI中证实这一点。

strComputer = "." 
Set objWMIService = GetObject("winmgmts:\" & strComputer & "
ootCIMV2") 
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法》是:

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

我在景观或肖像模式中获得了同样的价值观。

<><>UPDATE:

在多种监测环境中,你可以向所有监测员提供以下信息:

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}
问题回答

您可从<代码>Win32_VideoController中提取。 WMI 班级。 <代码>VideoModeDescription 包括屏幕分辨率和彩色深度。

(Get-WmiObject -Class Win32_VideoController).VideoModeDescription;

Result

1600 x 900 x 4294967296 colors

而对于平原,则与其他答案相同:

@Shay Levy的回答准确报告了威迪特/卡尔在权力轮会议启动时活跃的情况。 如果你在PS发射后轮流监测,则继续报告原先的、现在不正确的数值。

信息系统 班次为了解方向提供了另一种途径,即使展示在会议启动后轮值,也改变了目前的PS会议。

Add-Type -AssemblyName System.Windows.Forms
[System.Windows.Forms.SystemInformation]::ScreenOrientation
Angle0

[System.Windows.Forms.SystemInformation]::PrimaryMonitorSize
IsEmpty                            Width                           Height
-------                            -----                           ------
False                              1680                             1050

Rotate monitor, then...

[System.Windows.Forms.SystemInformation]::ScreenOrientation
Angle90

[System.Windows.Forms.SystemInformation]::PrimaryMonitorSize
IsEmpty                            Width                           Height
-------                            -----                           ------
False                              1050                             1680

https://msdn.microsoft.com/en-us/library/system.windows.forms.systeminformation(v=vs.110.aspx

这里的答案仅以沙伊斯为根据,按照欧佩斯的榜样,为每个屏幕形成结果。

PowerShell Code to format the results of: [System.Windows.Forms.Screen]::AllScreens

Add-Type -AssemblyName System.Windows.Forms
$screen_cnt  = [System.Windows.Forms.Screen]::AllScreens.Count
$col_screens = [system.windows.forms.screen]::AllScreens

$info_screens = ($col_screens | ForEach-Object {
if ("$($_.Primary)" -eq "True") {$monitor_type = "Primary Monitor    "} else {$monitor_type = "Secondary Monitor  "}
if ("$($_.Bounds.Width)" -gt "$($_.Bounds.Height)") {$monitor_orientation = "Landscape"} else {$monitor_orientation = "Portrait"}
$monitor_type + "(Bounds)                          " + "$($_.Bounds)"
$monitor_type + "(Primary)                         " + "$($_.Primary)"
$monitor_type + "(Device Name)                     " + "$($_.DeviceName)"
$monitor_type + "(Bounds Width x Bounds Height)    " + "$($_.Bounds.Width) x $($_.Bounds.Height) ($monitor_orientation)"
$monitor_type + "(Bits Per Pixel)                  " + "$($_.BitsPerPixel)"
$monitor_type + "(Working Area)                    " + "$($_.WorkingArea)"
}
)

Write-Host "TOTAL SCREEN COUNT: $screen_cnt"
$info_screens

Output for the secondary monitor in landscape mode. 1920 x 1200

# TOTAL SCREEN COUNT: 2
# Primary Monitor    (Bounds)                          {X=0,Y=0,Width=2560,Height=1600}
# Primary Monitor    (Primary)                         True
# Primary Monitor    (Device Name)                     \.DISPLAY1
# Primary Monitor    (Bounds Width x Bounds Height)    2560 x 1600 (Landscape)
# Primary Monitor    (Bits Per Pixel)                  32
# Primary Monitor    (Working Area)                    {X=0,Y=0,Width=2560,Height=1560}
# Secondary Monitor  (Bounds)                          {X=2560,Y=0,Width=1920,Height=1200}
# Secondary Monitor  (Primary)                         False
# Secondary Monitor  (Device Name)                     \.DISPLAY2
# Secondary Monitor  (Bounds Width x Bounds Height)    1920 x 1200 (Landscape)
# Secondary Monitor  (Bits Per Pixel)                  32
# Secondary Monitor  (Working Area)                    {X=2560,Y=0,Width=1920,Height=1160}

Output for the secondary monitor in portrait mode. 1200 x 1920

# TOTAL SCREEN COUNT: 2
# Primary Monitor    (Bounds)                          {X=0,Y=0,Width=2560,Height=1600}
# Primary Monitor    (Primary)                         True
# Primary Monitor    (Device Name)                     \.DISPLAY1
# Primary Monitor    (Bounds Width x Bounds Height)    2560 x 1600 (Landscape)
# Primary Monitor    (Bits Per Pixel)                  32
# Primary Monitor    (Working Area)                    {X=0,Y=0,Width=2560,Height=1560}
# Secondary Monitor  (Bounds)                          {X=2560,Y=0,Width=1200,Height=1920}
# Secondary Monitor  (Primary)                         False
# Secondary Monitor  (Device Name)                     \.DISPLAY2
# Secondary Monitor  (Bounds Width x Bounds Height)    1200 x 1920 (Portrait)
# Secondary Monitor  (Bits Per Pixel)                  32
# Secondary Monitor  (Working Area)                    {X=2560,Y=0,Width=1200,Height=1880}

你们可以借助这一指挥手段获得所有决议:

$Query = "SELECT * FROM CIM_VideoControllerResolution"
$res = Get-WMIObject -query $Query | Select Caption

就短期而言,这给你带来了第一个屏幕(如果你有很多)宽度和高度。

$height = (((Get-WmiObject -Class Win32_VideoController).VideoModeDescription  -split  
 )[0]  -split    )[2]
$width = (((Get-WmiObject -Class Win32_VideoController).VideoModeDescription  -split  
 )[0]  -split    )[0]




相关问题
Mutually exclusive powershell parameters

SCENARIO I m writing a cmdlet for Powershell 2.0 using Visual Studio 2008 and .NET 3.5 the cmdlet requires 3 arguments. my intended grammar of the cmdlet is something like this: cmdletname [foo|...

Run a program from PowerShell with timeout

I ll write a script that runs a program and wait for it finished. But if the program is not finished within a specified time I want that the program is killed.

How to transpose data in powershell

I have a file that looks like this: a,1 b,2 c,3 a,4 b,5 c,6 (...repeat 1,000s of lines) How can I transpose it into this? a,b,c 1,2,3 4,5,6 Thanks

Powershell v2 remoting and delegation

I have installed Powershell V2 on 2 machines and run Enable-PsRemoting on both of them. Both machines are Win 2003 R2 and are joined to the same active directory domain and I can successfully run ...

PowerShell -match operator and multiple groups

I have the following log entry that I am processing in PowerShell I m trying to extract all the activity names and durations using the -match operator but I am only getting one match group back. I m ...

热门标签