get resolution of 2nd monitor via script

181 views
Skip to first unread message

Matt Lind

unread,
Jul 6, 2009, 10:18:34 PM7/6/09
to soft...@listproc.autodesk.com
Hey all.
I've been trying to figure out how to get the resolution of the
user's monitors via script (JScript) as I need to write some tools that
place/resize PPGs in specific ways on the screen. Using a WMIService
query, I've been able to get the primary monitor's configuration, but I
cannot find a way to get the 2nd monitor's info. Unfortunately, I
cannot assume the 2nd monitor is the same as the 1st. Anybody have any
ideas?

I'd like to keep my code simple and homogenous, which means a solution
using JScript and doesn't require installation of any 3rd party tools.

thanks,

Matt


PS - here's how I get the primary monitor's info:

// Jscript
/*
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;
}
*/


Jon Swindells

unread,
Jul 6, 2009, 11:50:54 PM7/6/09
to soft...@listproc.autodesk.com
I can't test it at the moment but i've a feeling you should be in Win32_DeskTopMonitor

http://msdn.microsoft.com/en-us/library/aa394122(VS.85).aspx

2009/7/7 Matt Lind <ml...@carbinestudios.com>



--
Jon Swindells
squ...@gmail.com

Jon Swindells

unread,
Jul 7, 2009, 12:05:02 AM7/7/09
to soft...@listproc.autodesk.com
GetMonitorResolution();

function GetMonitorResolution()
{
       var wbemFlagReturnImmediately = 0x10;

       var Mode        = wbemFlagReturnImmediately;
       var Query       = "Select * from Win32_DeskTopMonitor";

       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.ScreenWidth + ", " +
oItem.ScreenHeight );
       }

       return;
}
////////////////////////////////////////////////////////////

Win32_VideoController is the actual physical gfx card

As i said, i can't test it at the moment unless someone sends me a nice 2nd monitor (will accept cash equivalent) :D


2009/7/7 Matt Lind <ml...@carbinestudios.com>



--
Jon Swindells
squ...@gmail.com

Matt Lind

unread,
Jul 7, 2009, 1:55:34 PM7/7/09
to soft...@listproc.autodesk.com
I tried everything with the word "Display", "Video", "Monitor", and "Desktop" in it.  Seems like no matter what I query I always get the primary monitor, and no additional information for the secondary monitor.
 
 
Matt
 
 


From: softimag...@listproc.autodesk.com [mailto:softimag...@listproc.autodesk.com] On Behalf Of Jon Swindells
Sent: Monday, July 06, 2009 9:05 PM
To: soft...@listproc.autodesk.com
Subject: Re: get resolution of 2nd monitor via script

Jon Swindells

unread,
Jul 7, 2009, 8:19:00 PM7/7/09
to soft...@listproc.autodesk.com
Have you tried using some of the flags in your query ?

select * from win32_DesktopMonitor where Availability = 3 //is on


any reason you can't write the plug in c# ?



2009/7/7 Matt Lind <ml...@carbinestudios.com>



--
Jon Swindells
squ...@gmail.com

Matt Lind

unread,
Jul 7, 2009, 9:01:58 PM7/7/09
to soft...@listproc.autodesk.com
>> Have you tried using some of the flags in your query ?
I have now.  No change in result unfortunately. :-(
 
 
>> any reason you can't write the plug in c# ?
 
I don't use C#.
 
I write 95% of my tools in JScript because it comes with XSI, is cross platform, and doesn't require additional software to be installed to do most things.  For the other 5%, typically performance related stuff, I use C/C++.
 
 
Matt
 
 


Sent: Tuesday, July 07, 2009 5:19 PM

Jon Swindells

unread,
Jul 8, 2009, 2:10:26 AM7/8/09
to soft...@listproc.autodesk.com
:(

i wasn't trying to sway you to the dark side ;)

after a quick google there seemed to be lots of people with exactly the same problem as you. other than trawling the registry i wouldn't know how to solve this
bugger. In C# I'd just use the Screen namespace and be done with it.

Maybe someone else has some experience/insight into the magical world of wmi




2009/7/8 Matt Lind <ml...@carbinestudios.com>

>> Have you tried using some of the flags in your query ?
I have now.  No change in result unfortunately. :-(
 
 
>> any reason you can't write the plug in c# ?
 
I don't use C#.
 
I write 95% of my tools in JScript because it comes with XSI, is cross platform, and doesn't require additional software to be installed to do most things.  For the other 5%, typically performance related stuff, I use C/C++.
 
 
Matt
 
 




--
Jon Swindells
squ...@gmail.com

Matt Lind

unread,
Jul 8, 2009, 5:59:18 PM7/8/09
to soft...@listproc.autodesk.com
I've got nothing against C#.  Just never had a need for it.
 
Yes, I've seen a lot people have the same problem.  Would it be easier to write a C++ plugin to grab the display details through OpenGL or some other Graphics API?
 
Matt
 
 


Sent: Tuesday, July 07, 2009 11:10 PM

To: soft...@listproc.autodesk.com
Subject: Re: get resolution of 2nd monitor via script

Jon Swindells

unread,
Jul 8, 2009, 10:05:10 PM7/8/09
to soft...@listproc.autodesk.com
I would have thought bog standard GDI calls would do the trick rather than messing around in ogl.

It definitely breaks your simplicity of staying with a portable language but as a temporary stopgap ( until a jscript soloution is found) i'd say it's the only way to keep some sanity :)



2009/7/9 Matt Lind <ml...@carbinestudios.com>



--
Jon Swindells
squ...@gmail.com

Luc-Eric Rousseau

unread,
Jul 8, 2009, 10:47:50 PM7/8/09
to soft...@listproc.autodesk.com
There is nothing in OpenGL about monitor resolution, it's platform independent.

http://msdn.microsoft.com/en-us/library/dd145072(VS.85).aspx

Reply all
Reply to author
Forward
0 new messages