gpt4 book ai didi

batch-file - 根据屏幕分辨率执行脚本

转载 作者:行者123 更新时间:2023-12-01 07:42:24 25 4
gpt4 key购买 nike

我试图在其他一些线程上找到答案,但我认为我正在尝试做的事情有点“具体”。我对批处理还不够好,无法改编/连接我发现的部分脚本......

因此,我正在尝试根据正在运行的屏幕分辨率执行命令。上下文如下;

登录时执行的命令专门将快捷方式放在桌面上,但分辨率之间的位置不同...

想法是定义一个变量,它是wmic desktopmonitor get screenheight, screenwidth 请求的答案。然后如果输出包含 1080,则执行此 cmd,否则如果它包含 720,则执行另一个,等等...

这就是我用于 win7 的 cmd(工作);

for /f "tokens=1-2 delims= " %%r in ('wmic desktopmonitor get screenheight^,  screenwidth ^| findstr "1"') do set current_res=%%sx%%r
if "%current_res%" == "1920x1080" C:\Windows\kiosque\desktopok.exe /load /silent c:\windows\kiosque\dispo_icones_1080p.dok

我需要用 wmic 路径 Win32_VideoController get VideoModeDescription 对 win10 做同样的事情,但我没有找到如何将此请求的输出正确定义为变量...

最佳答案

您需要不同的 wmic 查询,具体取决于 windows 版本。这是一个取决于版本的分辨率 getter :

@echo off
::https://en.wikipedia.org/wiki/List_of_Microsoft_Windows_versions
setlocal
for /f "tokens=4,5 delims=. " %%a in ('ver') do set "version=%%a%%b"


if version lss 62 (
::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%
::if "%x%x%y%" == "1920x1080" C:\Windows\kiosque\desktopok.exe /load /silent c:\windows\kiosque\dispo_icones_1080p.dok

endlocal

对于 Windows 7 或更早版本,您需要 desktopmonitor 类,对于较新的 Windows 版本,您需要 Win32_VideoController 。您可以尝试使用 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

关于batch-file - 根据屏幕分辨率执行脚本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49820720/

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