找到双屏分辨率

时间:2016-03-04 13:30:24

标签: powershell screen-resolution

我正在寻找一种在具有双显示器的计算机上获得总分辨率的方法。我已经找到了通过this stackoverflow page(这是我的问题)做到这一点的方法,但我在下面提出的解决方案非常笨重。

$screen = [System.Windows.Forms.Screen]::AllScreens | select -ExpandProperty bounds
foreach ($item in $screen)
{
    $item = $item -replace ".*Y=0,","" -replace "{", "" -replace "}", "" -replace "Width=", "" -replace "Height=", "" -replace ",", ";"
    $pos = $item.IndexOf(";")
    $leftPart = $item.Substring(0, $pos)
    $rightPart = $item.Substring($pos + 1)
    [int]$SCREENWIDTH = $SCREENWIDTH + $leftPart
    [int]$SCREENHEIGHT = $rightPart
}
$richtextbox1.Text = ([string]$SCREENWIDTH + " " + [string]$SCREENHEIGHT)

来自:

的输出
$screen = [System.Windows.Forms.Screen]::AllScreens | select -ExpandProperty bounds

{X=1920,Y=0,Width=1920,Height=1200} {X=0,Y=0,Width=1920,Height=1200}

所需的输出是将总宽度和高度存储到变量中。

我正在使用powershell studio。

1 个答案:

答案 0 :(得分:0)

只需确保初始化$ screenwidth

$screen = [System.Windows.Forms.Screen]::AllScreens | select -ExpandProperty bounds
$SCREENWIDTH = 0
foreach ($item in $screen)
{
    $item = $item -replace ".*Y=0,","" -replace "{", "" -replace "}", "" -replace "Width=", "" -replace "Height=", "" -replace ",", ";"
    $pos = $item.IndexOf(";")
    $leftPart = $item.Substring(0, $pos)
    $rightPart = $item.Substring($pos + 1)

    [int]$SCREENWIDTH = $SCREENWIDTH + $leftPart
    [int]$SCREENHEIGHT = $rightPart
}

([string]$SCREENWIDTH + " " + [string]$SCREENHEIGHT)