2016-01-20 98 views
1

我最近开始潜水编写批处理文件,我有一个问题。我试图创建一个文件来检查我的辅助监视器是否已连接,并且是否将主显示切换到辅助屏幕。 (是的,我知道关于Windows + P的快捷方式)...如何在批处理文件中检测多个监视器

到目前为止,我已经知道“DisplaySwitch.exe/external”将默认显示器设置为辅助监视器,但我无法找到如何检测是否显示在那里。

-Cheers,卢克

回答

1

一种可能的方式是使用dxdiag虽然不是最快的方法:

@echo off 

del ~.txt /q /f >nul 2>nul 
dxdiag /t ~ 
w32tm /stripchart /computer:localhost /period:1 /dataonly /samples:3 >nul 2>&1 
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 

会打印出所有显示器的分辨率。

更新:所有显示器

输入dxdiag打印信息,以便您可以检查是否有多个显示器:

@echo off 
del ~.txt /q /f >nul 2>nul 
start "" /w dxdiag /t ~ 

for /f "tokens=1* delims=:" %%a in ('find /c "Current Mode:" "~.txt"') do (
    set /a "number_of_monitors=%%b" 
    rem echo #%%b# 
) 
rem exit /b 0 
echo %number_of_monitors% 


rem :---- if it needed -----: 

if defined number_of_monitors (if %number_of_monitors% GTR 1 (echo second monitor connected) else (echo only one monitor connected)) 
del ~.txt /q /f >nul 2>nul 
+0

好了,所以这会产生一个文件,我的电脑的所有功能...我问如何做一个批处理该文件检查我的辅助监视器是否连接,使辅助监视器成为主监视器。我错过了你的观点吗? –

+0

@LukeRector - 检查我的update.It打印一条消息,如果有多个监视器。 – npocmaka

0

@ npocmaka的回答也不太为我工作,但这种他的代码没有变化(视窗10):

rem @echo off 
del %TEMP%\dxdiag.txt /q /f >nul 2>nul 
start "" /w dxdiag -64bit -t %TEMP%\dxdiag.txt 

for /f "tokens=3" %%f in ('find /c"Monitor Name:" %TEMP%\dxdiag.txt') do set MONITOR_COUNT=%%f 

if defined MONITOR_COUNT (if %MONITOR_COUNT% GTR 1 (echo second monitor connected) else (echo only one monitor connected)) 
del %TEMP%\monitors.txt /q /f >nul 2>nul 
相关问题