Reputation: 77
I'm trying to figure out a method of detecting if a users resolution is higher or lower than "1280 x 1024" through a batch file.
If the resolution is "1280 x 1024" or higher then do A. Otherwise do B.
Does anyone have any idea how this could be done?
Cheers,
Elliott
Upvotes: 4
Views: 3635
Reputation: 4037
In my case the wmic desktopmonitor
returns nothing.
This one works for me on Win 8.1
@ECHO OFF
for /f "delims=" %%# in ('"wmic path Win32_VideoController get CurrentHorizontalResolution,CurrentVerticalResolution /format:value"') do (
set "%%#">nul
)
echo %CurrentHorizontalResolution%
echo %CurrentVerticalResolution%
Upvotes: 0
Reputation: 3685
As an alternative to registry, you can also check resolution via Wmic
:
wmic desktopmonitor where availability=3 get screenHeight,screenWidth
More on the Win32_DesktopMonitor class here: http://msdn.microsoft.com/en-us/library/windows/desktop/aa394122%28v=vs.85%29.aspx
Be wary that it's possible to get multiple lines if there is more than 1 monitor attached - you should handle those cases in your script.
Upvotes: 3
Reputation: 354516
This is a bit tricky for several reasons:
The resolution is in the registry, you can query that with reg.exe
. However, it's not really easy to find. For me it's under
HKLM\SYSTEM\CurrentControlSet\Control\Video\{7FD4F64D-A7B2-41A9-AEEB-835BE4473FFA}\0000
in DefaultSettings.XResolution
and DefaultSettings.YResolution
. However, the GUID likely varies depending on what video card and driver you have, so you'd have to iterate all under HKLM\SYSTEM\CurrentControlSet\Control\Video
.
What do you mean with a higher resolution? Would 1366 × 768 be higher than 1280 × 1024? Do you count total pixel count? Higher in one dimension? In both?
In any case, I cobbled together the following batch. Adapt if necessary. It produces the correct result on my machine, but I don't have that many to test on.
@echo off
setlocal enabledelayedexpansion
for /f "delims=" %%l in ('reg query HKLM\SYSTEM\CurrentControlSet\Control\Video') do (
reg query %%l\0000 /v DefaultSettings.XResolution >nul 2>&1
if not errorlevel 1 (
for /f "skip=1 tokens=3 delims= " %%x in ('reg query %%l\0000 /v DefaultSettings.XResolution') do (
set /a X=%%x
)
for /f "skip=1 tokens=3 delims= " %%x in ('reg query %%l\0000 /v DefaultSettings.YResolution') do (
set /a Y=%%x
)
)
)
echo Resolution: %X% × %Y%
if %X% GTR 1280 if %Y% GTR 1024 echo Greater than 1280 × 1024.
Upvotes: 1