web-dev-qa-db-ja.com

Windowsコマンドラインからディスプレイの解像度を取得する

コマンドラインから解像度を変更するプログラムに関するいくつかの提案を見てきました。ただし、表示したいだけで変更はしません。

Linuxでは、xrandrまたはxdpyinfoを使用してこの情報を取得できるので、そのようなものを探しています。

また、cygwinシェル内で動作させるためにも必要です。

20
Zitrax

これを試して:

wmic desktopmonitor get screenheight, screenwidth

Cygwin内から:

cmd /c wmic desktopmonitor get screenheight, screenwidth

出力を使用するためにどのトリックを使用するべきかわかりません。おそらく一時的なテキストファイルですか?

21
paradroid

dxdiag を使用した場合、これは最速の方法ではありません。

@echo off

del ~.txt /q /f >nul 2>nul
start "" /w dxdiag /t ~
setlocal enableDelayedExpansion
set currmon=1 
for /f "tokens=2 delims=:" %%a in ('find "Current Mode:" ~.txt') do (
    echo Monitor !currmon! : %%a
    set /a currmon=currmon+1

)
endlocal
del ~.txt /q /f >nul 2>nul

これにより、すべてのモニターの解像度が印刷されます。

編集。受け入れられた回答はWMICを使用しています。 (wmic desktopmonitor get screenheight, screenwidth /format:value)これは、windows8/8.1/10では機能しません。新しいWindowsバージョンでは、これを使用できます。

wmic path Win32_VideoController get VideoModeDescription,CurrentVerticalResolution,CurrentHorizontalResolution /format:value

Windowsのバージョンを確認し、wmicで解像度を取得するスクリプト:

@echo off

setlocal
for /f "tokens=4,5 delims=. " %%a in ('ver') do set "version=%%a%%b"


if version lss 62 (
    ::set "wmic_query=wmic desktopmonitor get screenheight, screenwidth /format:value"
    for /f "tokens=* delims=" %%@ in ('wmic desktopmonitor get screenwidth /format:value') do (
        for /f "tokens=2 delims==" %%# in ("%%@") do set "x=%%#"
    )
    for /f "tokens=* delims=" %%@ in ('wmic desktopmonitor get screenheight /format:value') do (
        for /f "tokens=2 delims==" %%# in ("%%@") do set "y=%%#"
    )

) else (
    ::wmic path Win32_VideoController get VideoModeDescription,CurrentVerticalResolution,CurrentHorizontalResolution /format:value
    for /f "tokens=* delims=" %%@ in ('wmic path Win32_VideoController get CurrentHorizontalResolution  /format:value') do (
        for /f "tokens=2 delims==" %%# in ("%%@") do set "x=%%#"
    )
    for /f "tokens=* delims=" %%@ in ('wmic path Win32_VideoController get CurrentVerticalResolution /format:value') do (
        for /f "tokens=2 delims==" %%# in ("%%@") do set "y=%%#"
    )

)

echo Resolution %x%x%y%

endlocal
10
npocmaka

ありがとう@paradroid :) WMICを使用して、フルスクリーンではなく便利なリモートデスクトップにバッチスクリプトを作成しました。 ^ _ ^

@echo off
:p00
setlocal
if "%1"=="" goto :q01
set i01=wmic desktopmonitor
set i01=%i01% where availability^=3
set i01=%i01% get screenHeight,screenWidth
set o01=%temp%\ScrRes.txt
%i01%>"%o01%"
for /f "delims= skip=1" %%o in ('type %o01%') do call :p01 %1 %%o
goto :p99

:p01
set srvnm=%1
set /a tl=%2-40
set /a ll=%3-80
start mstsc /admin /w:%ll% /h:%tl% /v:%srvnm%
goto :eof

:q01
echo.
echo ^>^> Syntax: %0 MachineHostname [enter]
echo.

:p99
if exist "%o01%" del "%o01%" /f /q
echo.
echo ^>^> Sincerely Thank You For Using..
endlocal
goto :eof

自由に探索してください。エンスージアストに強化してもらいます。 (y)

2
Rhak Kahr

最も簡単な方法:

@echo off
::By SachaDee 2018

FOR /F "skip=2 delims=" %%a IN ('wmic path Win32_VideoController get VideoModeDescription^,CurrentHorizontalResolution^,CurrentVerticalResolution /format:Value ^| findstr ":"') do set %%a

echo Width =^> %CurrentHorizontalResolution%
echo Height =^> %CurrentVerticalResolution%
echo Description =^> %VideoModeDescription%
1
SachaDee

マルチモニターセットアップの場合は、コマンドを分割するだけです。

setlocal ENABLEDELAYEDEXPANSION
setlocal ENABLEEXTENSIONS
set wmicheight="wmic desktopmonitor get screenheight /format:value"
set wmicwidth="wmic desktopmonitor get screenwidth /format:value"
:height
for /f "tokens=2 delims==" %%a in ('%wmicheight%') do (
    If %%a LEQ 1 (
        rem skip if height is not bigger than 1
    ) Else (
        rem take the first height value larger than 1
        rem then skip to width
        Set /a "height=%%a"
        goto :width
    )
)
:width
for /f "tokens=2 delims==" %%a in ('%wmicwidth%') do (
    If %%a LEQ 1 (
        rem skip if width is not bigger than 1
    ) Else (
        rem add width found to get total width of all screens
        Set /a "width=width+%%a"
    )
)
echo %width% x %height%
1
Rob Moore

MultiMonitorTool を使用:

MultiMonitorTool.exe /scomma "%TEMP%\MultiMonitorTool.csv"

次に、ファイル「%TEMP%\ MultiMonitorTool.csv」を解析します(私はまだこれに取り組んでいます)

1
eadmaster

最も古い答えはもう機能していないようです(win7 64ビット)。私はそのように解決しました

FOR /f "tokens=1,2" %%a IN ('"wmic desktopmonitor get screenheight, screenwidth"') DO (
    SET /a ScreenHeight=%%a
    SET /a ScreenWidth=%%b
)
echo %ScreenHeight%
echo %ScreenWidth%
1
Lesto

これは私の試みです:

@echo off
Mode 45,3 & color 0A
Title Dislpay Resolution by Hackoo 2018
Set "WMIC_Command=wmic path Win32_VideoController get VideoModeDescription^,CurrentHorizontalResolution^,CurrentVerticalResolution /format:Value"
Set "H=CurrentHorizontalResolution"
Set "V=CurrentVerticalResolution"
Call :GetResolution %H% HorizontalResolution
Call :GetResolution %V% VerticalResolution
echo(
echo     Screen Resolution is : %HorizontalResolution% x %VerticalResolution%
pause>nul & Exit
::****************************************************
:GetResolution 
FOR /F "tokens=2 delims==" %%I IN (
  '%WMIC_Command% ^| find /I "%~1" 2^>^nul'
) DO FOR /F "delims=" %%A IN ("%%I") DO SET "%2=%%A"
Exit /b
::****************************************************
0
Hackoo