Getting the screen resolution


This snippet uses WMI to get the screen resolution.

GetMonitorResolution();

function GetMonitorResolution()
{
       var wbemFlagReturnImmediately = 0x10;

       var Mode        = wbemFlagReturnImmediately;
       var Query       = "Select * from Win32_VideoController";
       var oWMIService = GetObject( "winmgmts:\\\\.\\root\\cimv2" );
       var oCollection = oWMIService.ExecQuery( Query, "WQL", Mode );

       var oItems = new Enumerator( oCollection );

       for ( ; !oItems.atEnd(); oItems.moveNext() ) {

               var oItem = oItems.item();

               // dump info
               LogMessage( "Resolution [x,y]: " +
				oItem.CurrentHorizontalResolution + ", " +
				oItem.CurrentVerticalResolution );
       }

       return;
}

For me, this script outputs the resolution of both monitors:

// INFO : Resolution [x,y]: 1280, 1024
// INFO : Resolution [x,y]: 1920, 1200

Credit: Matt Lind, on the XSI mailing list

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s