Answers:
尝试这个:
wmic desktopmonitor get screenheight, screenwidth
从Cygwin内部:
cmd /c wmic desktopmonitor get screenheight, screenwidth
我不确定要使用什么技巧才能使用输出。也许是临时文本文件?
使用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
这将打印所有显示器的分辨率。
编辑。接受的答案使用WMIC。(wmic desktopmonitor get screenheight, screenwidth /format:value
)。在Windows8 / 8.1 / 10上不起作用。对于较新的Windows版本,可以使用:
wmic path Win32_VideoController get VideoModeDescription,CurrentVerticalResolution,CurrentHorizontalResolution /format:value
一个脚本,该脚本检查Windows版本,然后使用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
谢谢@paradroid :)使用WMIC,我没有以全屏方式向远程桌面编写批处理脚本,但仍然很方便。^ _ ^
@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
随意探索。感到发烧友增强。(y)
MultiMonitorTool.exe /scomma "%TEMP%\MultiMonitorTool.csv"
然后解析文件“%TEMP%\ MultiMonitorTool.csv”(我仍在处理)
对于多监视器设置,只需拆分命令:
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%
最简单的方法:
@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%
/format:Value
以var = value形式返回结果,然后在set
命令中使用它。如果您只想要一个值,是否可以在没有for循环的情况下执行此操作?
wmic
使用正确的参数单独运行查询即可显示该值。for
此处将循环用于set
这些值,以供以后在代码中使用。这是bat
使用外部命令(wmic.exe
在这种情况下)的唯一方法。
set
一个wmic
没有for循环的结果?
这是我的尝试:
@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
::****************************************************