从Windows命令行获取显示分辨率

从Windows命令行获取显示分辨率

我见过一些关于从命令行更改分辨率的程序的建议。但我只想显示它,而不是更改它。

在 Linux 上,我可以使用xrandrxdpyinfo来获取此信息,因此我正在寻找类似的东西。

我还需要它在 cygwin shell 中工作。

答案1

尝试这个:

wmic desktopmonitor get screenheight, screenwidth

从 Cygwin 内部:

cmd /c wmic desktopmonitor get screenheight, screenwidth

编辑:更新至更高版本的 Windows

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

编辑:wmic 已被弃用

在 PowerShell 中:

 Get-CimInstance -ClassName Win32_VideoController | Select-Object VideoModeDescription

(使用Get-CimInstance而不是Get-WmiObject因为这可能会很快被弃用)

答案2

诊断工具虽然这不是最快的方法:

@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

答案3

谢谢@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)

答案4

最老的答案似乎不再起作用了(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%

相关内容