19

I have seen several suggestions about programs to change the resolution from the command line. However I just want to display it, not change it.

On linux I can use xrandr or xdpyinfo to get this info, so I am looking for something like that.

I also need it to work within a cygwin shell.

  • 2
    Note: There is also a PowerShell version available if anyone is interested. Over at StackOverflow they also solved the multimonitor problem – nixda Jun 7 '15 at 7:21
20

Try this:

wmic desktopmonitor get screenheight, screenwidth

From within Cygwin:

cmd /c wmic desktopmonitor get screenheight, screenwidth

I'm not sure what tricks to use in order to use the output. Perhaps a temporary text file?

  • Yes thanks it works from cmd.exe. However I forgot to mention that I need this to work inside a cygwin shell and wmic do not seem to work there. – Zitrax Apr 15 '11 at 9:30
  • 1
    @Zitrax: Now you tell me. – paradroid Apr 15 '11 at 9:52
  • Thanks again. It did not work when connecting with rdesktop (or ssh into cygwin) though. Would be great to have it in all those situations also. – Zitrax Apr 15 '11 at 20:16
  • 2
    Does not work on Win8.1 or win10. It gives empty results for both screenheight and screenwidth. – David Balažic Feb 8 '18 at 17:36
  • 1
    @paradroid It does not work, as explained in the other answer – David Balažic Feb 9 '18 at 11:43
10

With dxdiag though it is not the fastest way:

@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

this will print the resolutions of all monitors.

Edit. The accepted answer uses WMIC. (wmic desktopmonitor get screenheight, screenwidth /format:value).This will not work on windows8/8.1/10. For the newer windows versions this can be used:

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

A script that checks the windows version and then gets the resolution with the 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
2

Thank you @paradroid :) With WMIC, I wrote Batch Script to Remote Desktop not full screen but still convenient. ^_^

@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

Feel free to explore. Feel enthusiast to enhance. (y)

1

use MultiMonitorTool:

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

then parse the file "%TEMP%\MultiMonitorTool.csv" (i'm still working on this)

1

the oldes answer does not seems to work anymore (win7 64bit); i solved that way

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

For multi monitor setup just split the command:

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%
  • Please use code blocks. You've been a member here long enough to know how markdown works and how to make it look readable. – Karan Jun 7 '15 at 7:16
1

The simplest way :

@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%
  • Can you give a little more explanation into what's going on here? I understand /format:Value returns results in a var=value form which is then used in the set command. If you just want one value, is there a way to do this without the for loop? – Kyle Delaney Jun 19 '18 at 14:40
  • If you just want to display the needed value, you can for sure just run a wmic query alone with the right parameters to just display the value. The for loop is used here to set the values for a later use in the code. That's the only way to do it in bat using an external command (wmic.exe in this case). – SachaDee Jun 19 '18 at 21:14
  • You can't use set with a wmic result without a for loop? – Kyle Delaney Jun 19 '18 at 21:15
  • No its not possible ! – SachaDee Jun 19 '18 at 21:20
0

This is my try :

@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
::****************************************************

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.