根据屏幕分辨率

时间:2018-04-13 15:42:16

标签: batch-file screen-resolution

我试图在其他一些主题上找到答案,但我认为我试图做的事情有点特定"。我不太适合批量调整/连接我发现的脚本部分...

所以,我试图执行命令,具体取决于运行的屏幕分辨率。 上下文如下;

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

这个想法是定义一个变量,这是 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获取VideoModeDescription 对win10执行相同的操作,但我还没有找到如何将此请求的输出正确定义为变量... < / p>

2 个答案:

答案 0 :(得分:2)

由于Win32_VideoController已在我的Windows 7Windows 10系统中进行了测试,因此以下是一些Win32_VideoController示例:

检索水平分辨率,在您的问题中暗示为决定因素

For /F "Delims=" %%A In (
    'WMIC Path Win32_VideoController Get CurrentHorizontalResolution'
) Do For %%B In (%%A) Do Set "ResW=%%B"

同样,如果您只想检查垂直分辨率:

For /F "Delims=" %%A In (
    'WMIC Path Win32_VideoController Get CurrentVerticalResolution'
) Do For %%B In (%%A) Do Set "ResH=%%B"

如果您想要WxH格式的分辨率:

@Echo Off
Set "WP=Path Win32_VideoController"
Set "WV=CurrentHorizontalResolution,CurrentVerticalResolution"

For /F "Skip=1 Tokens=*" %%A In ('"WMIC %WP% Get %WV%"'
) Do For /F "Tokens=1-2" %%B In ("%%A") Do Set ScRes=%%Bx%%C
Echo=%ScRes%
Pause

如果您想要一个同时兼顾DesktopMonitor和Win32_VideoController的版本,那么可能会这样做,(从Vista开始)

@Echo Off
Set "OV="
For /F "EOL=V" %%A In ('WMIc OS Get Version 2^>Nul'
) Do For /F "Tokens=1-2 Delims=." %%B In ("%%A") Do Set /A "OV=%%B%%C"
If Not Defined OV Exit /B
Set "ScRes=%%Cx%%B" & Set "WP=DesktopMonitor"
Set "WV=ScreenHeight,ScreenWidth"
If %OV% GEq 61 (Set "WP=Path Win32_VideoController" & Set "ScRes=%%Bx%%C"
    Set "WV=CurrentHorizontalResolution,CurrentVerticalResolution")
For /F "Skip=1 Tokens=*" %%A In ('"WMIC %WP% Get %WV%"'
) Do For /F "Tokens=1-2" %%B In ("%%A") Do Set ScRes=%ScRes%
Echo=%ScRes%
Pause

对于至少Windows 7的版本,我已将8留给GEq 61,因为正如我所说,它适用于我的Windows 7版本。
但是,您可以将其更改为Windows 8 / Server 2012及更高版本的Gtr 61,如果要将其限制为高于Windows 8.1 / Server 2012 R2的任何内容,则可以Gtr 63

答案 1 :(得分:1)

根据Windows版本,您需要不同的wmic查询。这是一个取决于版本的解决方案获取器:

@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