@echo off
set h=wmic desktopmonitor, get screenheight
set w=wmic desktopmonitor, get screenwidth
echo %h%
echo %w%
pause
而不是-
1600 2560
I get -
回波式桌面监视器,获取屏幕宽度
回波式台式机,获取屏幕高度
,我希望这个批处理脚本能够获得我的显示分辨率大小,并将其设置为高度和宽度变量,并能够在数字上回显。
,但它似乎不起作用。
发布于 2014-08-31 18:57:59
使用desktopmonitor
,您只能获得需要Win32_VideoController
的dpi.For像素分辨率:
@echo off
for /f "delims=" %%# in ('"wmic path Win32_VideoController get CurrentHorizontalResolution,CurrentVerticalResolution /format:value"') do (
set "%%#">nul
)
echo %CurrentHorizontalResolution%
echo %CurrentVerticalResolution%
如果你想我也可以添加一个dpi分辨率getter?如果有多个监视器,我就得修改剧本.
另一种允许您获得更多监视器分辨率的方法是使用DxDiag (尽管它将创建一个临时文件,并且速度更慢):
使用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
这将打印所有显示器的分辨率。
编辑:
将检测窗口版本并在需要时使用不同wmi类的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
发布于 2020-02-09 00:43:22
@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
发布于 2014-11-21 10:58:56
完成得很好:-)为了防止空集命令,我建议使用find添加这个小部分:
FOR /f "delims=" %%a IN ('%comspec% /c "wmic desktopmonitor get ScreenWidth,ScreenHeight" /value ^| find "="') DO (SET %%a)
https://stackoverflow.com/questions/25594848
复制相似问题