Skip navigation

JSI Tip 9573. How can a script return the actual and available screen size and color depth?


I have scripted ScreenSize.bat to return the actual and available screen size, and color depth.

The syntax for using ScreenSize.bat is:

ScreenSize Width Height AvailWidth AvailHeight ColorDepth

Where:

Width       is a call directed numeric environment variable that will contain the actual screen width.

Height      is a call directed numeric environment variable that will contain the actual screen height.

AvailWidth  is a call directed numeric environment variable that will contain the available screen width.
            If a vertical task bar is used, without auto-hide, AvailWidth=Width - TaskbarSize.
AvailHeight is a call directed numeric environment variable that will contain the available screen height. 
            If a horizontal task bar is used, without auto-hide, AvailHeight=Height - TaskbarSize.

ColorDepth   is a call directed numeric environment variable that will contain the color depth, in bits per pixel.
ScreenSize.bat contains:
@echo off
if \{%5\}==\{\} @echo Syntax: ScreenSize Width Height AvailWidth AvailHeight ColorDepth&goto :EOF
If exist "%TEMP%\ScreenSize.vbs" goto doit
@echo Dim IE, Scr>"%TEMP%\ScreenSize.vbs"
@echo Set IE = CreateObject("InternetExplorer.Application")>>"%TEMP%\ScreenSize.vbs"
@echo IE.visible = False>>"%TEMP%\ScreenSize.vbs"
@echo IE.Navigate("about:blank")>>"%TEMP%\ScreenSize.vbs"
@echo Do Until IE.ReadyState = 4 >>"%TEMP%\ScreenSize.vbs"
@echo Loop >>"%TEMP%\ScreenSize.vbs"
@echo Set Scr = IE.Document.parentWindow.screen >>"%TEMP%\ScreenSize.vbs"
@echo Wscript.Echo Scr.width ^& " " ^& Scr.height ^& " " ^& Scr.availwidth ^& " " ^& Scr.availheight ^& " " ^& Scr.colordepth >>"%TEMP%\ScreenSize.vbs"
@echo Set Scr = Nothing>>"%TEMP%\ScreenSize.vbs"
@echo IE.Quit>>"%TEMP%\ScreenSize.vbs"
@echo Set IE = Nothing>>"%TEMP%\ScreenSize.vbs"
:doit
for /f "Tokens=1-5" %%a in ('cscript //nologo "%TEMP%\ScreenSize.vbs"') do (
 set /a %1=%%a
 set /a %2=%%b
 set /a %3=%%c
 set /a %4=%%d
 Set /a %5=%%e
)



Hide comments

Comments

  • Allowed HTML tags: <em> <strong> <blockquote> <br> <p>

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.
Publish