加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > Windows > 正文

batch-file – BATCH – 从Windows命令行获取显示分辨率并设置变

发布时间:2020-12-14 01:35:23 所属栏目:Windows 来源:网络整理
导读:@echo offset h=wmic desktopmonitor,get screenheightset w=wmic desktopmonitor,get screenwidthecho %h%echo %w%pause 而不是得到 – 1600 2560 我明白了 – echo wmic desktopmonitor,获取screenwidth echo wmic desktopmonitor,获取屏幕高度 我希望这个
@echo off
set h=wmic desktopmonitor,get screenheight
set w=wmic desktopmonitor,get screenwidth
echo %h%
echo %w%
pause

而不是得到 –

1600
2560

我明白了 –

echo wmic desktopmonitor,获取screenwidth

echo wmic desktopmonitor,获取屏幕高度

我希望这个批处理脚本能够获得我的显示分辨率大小并将其设置为高度和宽度变量,并且能够回显数量.
但它似乎没有起作用.

解决方法

使用desktopmonitor,您只能获得dpi.对于像素分辨率,您需要Win32_VideoController:

@echo off

for /f "delims=" %%# in  ('"wmic path Win32_VideoController  get CurrentHorizontalResolution,CurrentVerticalResolution /format:value"') do (
  set "%%#">nul
)

echo %CurrentHorizontalResolution%
echo %CurrentVerticalResolution%

如果你想我也可以添加一个dpi分辨率吸气剂?
如果有多个显示器,我将不得不修改脚本……

另一种允许你获得更多监视器分辨率的方法是使用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

这将打印所有显示器的分辨率.

编辑:

一个wmic脚本,它将检测Windows的版本,并在需要时使用不同的wmi类:

@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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读