@echo off & setlocal enableextensions
::
:: Build a Visual Basic Script
set skip=
set vbs_=%temp%\tmp$$$.vbs
findstr "'%skip%VBS" "%~f0" > "%vbs_%"
::
:: Run the script with Microsoft Windows Script Host Version 5.6
for /f "tokens=1,2" %%a in ('cscript //nologo "%vbs_%"') do (
set width_=%%a
set height_=%%b)
::
:: Display the results
echo width_=%width_%
echo height_=%height_%
::
:: Clean up
for %%f in ("%vbs_%") do if exist %%f del %%f
if not defined cmdbox if defined PauseIfFromDesktop pause
endlocal & goto :EOF
'
On Error Resume Next 'VBS
Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2") 'VBS
Set colItems = objWMIService.ExecQuery ("Select * from Win32_DisplayConfiguration") 'VBS
For Each objItem in colItems 'VBS
WScript.StdOut.Write objItem.PelsWidth 'VBS
WScript.StdOut.Write " " & objItem.PelsHeight 'VBS
WScript.StdOut.WriteLine 'VBS
Next 'VBS
The output could be e.g.
C:\_D\TEST>CMDFAQ.CMD
width_=1440
height_=900