gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-04 02:26:43 27 4
gpt4 key购买 nike

@echo off
set h=wmic desktopmonitor, get screenheight
set w=wmic desktopmonitor, get screenwidth
echo %h%
echo %w%
pause

而不是得到 -

1600
2560

我得到 -

echo wmic desktopmonitor,获取屏幕宽度

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 分辨率 setter/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

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

编辑:

一个 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

关于batch-file - BATCH - 从 Windows 命令行获取显示分辨率并设置变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25594848/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com