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

Zit*_*rax 22 windows display cygwin resolution command-line

我已经看到了一些关于从命令行更改分辨率的程序的建议。但是我只想显示它,而不是改变它。

在 linux 上我可以使用xrandrxdpyinfo获取这些信息,所以我正在寻找类似的东西。

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

par*_*oid 21

尝试这个:

wmic desktopmonitor get screenheight, screenwidth
Run Code Online (Sandbox Code Playgroud)

从 Cygwin 内部:

cmd /c wmic desktopmonitor get screenheight, screenwidth
Run Code Online (Sandbox Code Playgroud)

我不确定要使用什么技巧才能使用输出。也许是一个临时文本文件?

  • 不适用于 Win8.1 或 win10。它给出了屏幕高度和屏幕宽度的空结果。 (3认同)
  • 对我来说,它无法在多显示器设置中正常工作(它总是返回第一个显示器的分辨率,即使它被禁用)(我的操作系统:WinXP)。 (2认同)
  • @paradroid 它不起作用,如 [other answer](https://superuser.com/a/1028773/86828) 中所述 (2认同)

npo*_*aka 12

使用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
Run Code Online (Sandbox Code Playgroud)

这将打印所有显示器的分辨率。

编辑。接受的答案使用 WMIC。( wmic desktopmonitor get screenheight, screenwidth /format:value). 这在 windows8/8.1/10 上不起作用。对于较新的 Windows 版本,可以使用:

wmic path Win32_VideoController get VideoModeDescription,CurrentVerticalResolution,CurrentHorizontalResolution /format:value
Run Code Online (Sandbox Code Playgroud)

检查 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
Run Code Online (Sandbox Code Playgroud)