2016-01-20 96 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 
相關問題