@echo off
set h=wmic desktopmonitor, get screenheight
set w=wmic desktopmonitor, get screenwidth
echo %h%
echo %w%
pause
Instead of getting -
1600 2560
I get -
echo wmic desktopmonitor, get screenwidth
echo wmic desktopmonitor, get screenheight
I want this batch script to be able to get my display resolution size and set it in height and width variable and able to be echo'd in number.
But it's not seem to be working.
Find your screen resolution by running a command in Command Prompt or PowerShell (all Windows versions) If you like using the Command Prompt or PowerShell, you can use the command wmic path Win32_VideoController get CurrentHorizontalResolution,CurrentVerticalResolution to find out what resolution your screen has.
Type CMD and press Enter in add “QRes” folder address bar to open Command Prompt in the location. In the command, make sure to change the path for the QRes.exe file, and enter a supported width (x) and height (y) pixel resolution. For example, 1366 x 768, 1440 x 900, 1680 x 1050, 1920 x 1080, 2560 x 1440, etc.
Go to 'settings,' then click 'system,' then click 'display,' then 'advanced display settings. ' The recommended resolution is your native resolution, and the one that you should be using.
with desktopmonitor
you can get only dpi.For pixel resolution you need Win32_VideoController
:
@echo off
for /f "delims=" %%# in ('"wmic path Win32_VideoController get CurrentHorizontalResolution,CurrentVerticalResolution /format:value"') do (
set "%%#">nul
)
echo %CurrentHorizontalResolution%
echo %CurrentVerticalResolution%
If you want I can add also a dpi resolution getter? And if have more than one monitors I'll have to modify the script...
Another way that will allow you to get resolution of more monitors is to use DxDiag (though it will create a temp file and will be slower ):
With 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
this will print the resolutions of all monitors.
EDIT:
A wmic script that will detect the version of windows and will use different wmi classes if needed:
@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
@echo off
title Detect Screen Resolution
REM Detect Screen Resolution in Windows 7 - 10 - 32/64 bit compatible.
REM You must have the proper graphics driver installed in your system.
set loop#=2
set /a loop=1
for /f "tokens=*" %%c in ('reg query "HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Hardware Profiles\UnitedVideo\CONTROL\VIDEO" ^| find "{"') do @set "Resolution-path=%%c" && goto next
for /f "tokens=*" %%c in ('reg query "HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Control\UnitedVideo\CONTROL\VIDEO" ^| find "{"') do @set "Resolution-path=%%c" && echo win 10 && goto next
:next
for /f "tokens=*" %%c in ('reg query "%Resolution-path%\0000" /v "DefaultSettings.XResolution" ^| find "0"') do @set "XResolution-HEX=%%c"
for /f "tokens=*" %%c in ('reg query "%Resolution-path%\0000" /v "DefaultSettings.YResolution" ^| find "0"') do @set "YResolution-HEX=%%c"
if %XResolution-HEX:~44% == 0x400 goto not1
if 0 == %XResolution-HEX:~44,-4% goto Y1
goto not1
:Y1
ver | find "6.1" > nul
if %ERRORLEVEL% == 0 echo %Resolution-path:~84% win 7 && goto next2
ver | find "6.2" > nul
if %ERRORLEVEL% == 0 echo %Resolution-path:~84% win 8 && goto next2
echo %Resolution-path:~74% win 10
:next2
echo %XResolution-HEX:~44%
echo %YResolution-HEX:~44%
if %XResolution-HEX:~44% == 0x780 echo . && if %YResolution-HEX:~44% == 0x438 set screen-resolution=1920x1080
if %XResolution-HEX:~44% == 0x6f0 echo . && if %YResolution-HEX:~44% == 0x3e8 set screen-resolution=1776x1000
if %XResolution-HEX:~44% == 0x690 echo . && if %YResolution-HEX:~44% == 0x41a set screen-resolution=1680x1050
if %XResolution-HEX:~44% == 0x640 echo . && if %YResolution-HEX:~44% == 0x384 set screen-resolution=1600x900
if %XResolution-HEX:~44% == 0x556 echo . && if %YResolution-HEX:~44% == 0x300 set screen-resolution=1366x768
if %XResolution-HEX:~44% == 0x550 echo . && if %YResolution-HEX:~44% == 0x300 set screen-resolution=1360x768
if %XResolution-HEX:~44% == 0x500 echo . && if %YResolution-HEX:~44% == 0x400 set screen-resolution=1280x1024
if %XResolution-HEX:~44% == 0x500 echo . && if %YResolution-HEX:~44% == 0x3c0 set screen-resolution=1280x960
if %XResolution-HEX:~44% == 0x500 echo . && if %YResolution-HEX:~44% == 0x300 set screen-resolution=1280x768
if %XResolution-HEX:~44% == 0x500 echo . && if %YResolution-HEX:~44% == 0x2d0 set screen-resolution=1280x720
if %XResolution-HEX:~44% == 0x480 echo . && if %YResolution-HEX:~44% == 0x288 set screen-resolution=1152x648
if %XResolution-HEX:~44% == 0x400 echo . && if %YResolution-HEX:~44% == 0x300 set screen-resolution=1024x768
if %XResolution-HEX:~44% == 0x320 echo . && if %YResolution-HEX:~44% == 0x258 set screen-resolution=800x600
setx screen-resolution "%screen-resolution%"
echo Detected screen resolution.
echo %screen-resolution%
echo.
echo.
pause
exit
:not1
if %loop% == %loop#% goto not
set /a loop=loop+1
for /f "tokens=*" %%c in ('reg query "HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Hardware Profiles\UnitedVideo\CONTROL\VIDEO" ^| find "{"') do @set "Resolution-path=%%c"
for /f "tokens=*" %%c in ('reg query "HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Control\UnitedVideo\CONTROL\VIDEO" ^| find "{"') do @set "Resolution-path=%%c" && echo win 10
goto next
:not
setlocal
color 4f
cd /d %~dp0
echo failed exiting
timeout /t 05
exit
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With