Get display resolution from windows command line
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?
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
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)