|
本帖最后由 hlowld 于 2024-5-30 15:01 编辑
在你的提醒下,观察了注册表,外接显示器显示模式切换以后,注册表中的确有变化,按照推测的规则写了一个批处理,办公室笔记本和外接显示器通过。待回家后再试下另外一台笔记本和显示器,看是否通用
@echo off & setlocal enabledelayedexpansion
set "parentkey=HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Control\GraphicsDrivers\Connectivity"
reg query "%parentkey%" 1>nul 2>nul && for /f "tokens=1-7 delims=\" %%a in ('reg query "%parentkey%"') do (
set "name=%%g"
set "key=%%a\%%b\%%c\%%d\%%e\%%f\%%g"
call :getlen !name!
set /a len1=!len!
call :getlen !name:^^=!
set /a len=!len!+2
if !len! equ !len1! (
call :reg_query !key! Recent
set "Recent=!REG_VALUE!"
for %%k in (Clone Internal External eXtend) do (
call :reg_query !key! %%k
if /i "!Recent!"=="!REG_VALUE!" (echo mode:%%k & goto :end)
)
)
)
:end
pause
exit
:reg_query
set "REG_VALUE="
if "%~1"=="" goto :eof
if "%~2"=="" goto :eof
for /f "skip=2 tokens=1,2,*" %%a in ('reg query "%~1" /v "%~2" 2^>nul') do set "REG_VALUE=%%c"
goto :eof
:getlen
set /a len=0
set "tstr=%1"
:loop
if defined tstr (
set /a len+=1
set "tstr=!tstr:~1!"
goto :loop
)
goto :eof
在HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Control\GraphicsDrivers\Connectivity下找有两个^的子项,看该子项下哪个键的值和Recent的相同,就说明当前是哪个模式 |
|