Tumulus

Retrieve Monitor Details

6 posts in this topic

I need to create a script that will read the maximum resolution available on the monitor currently connected to my machine. I then need to change the machines current height and width settings to those specifications. I have got the second part figured out (I think :/) but retriving the information from the monitor has got me stumped.

I have tried a lot of scripts lurking about in the forums, but I haven't got one to work yet. There are a lot of scripts out there to read the information into arrays using a struct or scripts that return a long host of monitor details, but I haven't been able to make them work. I can't seem to figure out exactly how they communicate with the monitor, and I would like to understand what is happening rather than simply copying code anyway.

So far my script looks like this. I don't know how to get the monitor information required for GetRes(). I'd be grateful for some help there! Thanks.

ChangeResolution.au3

Share this post


Link to post
Share on other sites



Have you tried scriptomatic.au3? It's in "..\AutoIt3\Examples\COM\Scriptomatic.au3" and generate scripts like this

; Generated by AutoIt Scriptomatic

$wbemFlagReturnImmediately = 0x10
$wbemFlagForwardOnly = 0x20
$colItems = ""
$sComputer = "localhost"

$Output=""
$Output = $Output & "Computer: " & $sComputer  & @CRLF
$Output = $Output & "==========================================" & @CRLF
$oWMIService = ObjGet("winmgmts:\\" & $sComputer & "\")
$colItems = $oWMIService.ExecQuery("SELECT * FROM CIM_VideoControllerResolution", "WQL", _
                                          $wbemFlagReturnImmediately + $wbemFlagForwardOnly)

If IsObj($colItems) Then
   For $objItem In $colItems
      $Output = $Output & "Caption: " & $objItem.Caption & @CRLF
      $Output = $Output & "Description: " & $objItem.Description & @CRLF
      $Output = $Output & "HorizontalResolution: " & $objItem.HorizontalResolution & @CRLF
      $Output = $Output & "MaxRefreshRate: " & $objItem.MaxRefreshRate & @CRLF
      $Output = $Output & "MinRefreshRate: " & $objItem.MinRefreshRate & @CRLF
      $Output = $Output & "NumberOfColors: " & $objItem.NumberOfColors & @CRLF
      $Output = $Output & "RefreshRate: " & $objItem.RefreshRate & @CRLF
      $Output = $Output & "ScanMode: " & $objItem.ScanMode & @CRLF
      $Output = $Output & "SettingID: " & $objItem.SettingID & @CRLF
      $Output = $Output & "VerticalResolution: " & $objItem.VerticalResolution & @CRLF
      If MsgBox(1,"WMI Output",$Output) = 2 Then ExitLoop
      $Output=""
   Next
Else
   MsgBox(0,"WMI Output","No WMI Objects Found for class: " & "CIM_VideoControllerResolution" )
EndIf

 

Share this post


Link to post
Share on other sites

I haven't tried that yet. I'll give it a shot and let ya know.

Share this post


Link to post
Share on other sites

Generated script can easily modified:

#include <Array.au3>
#include <File.au3>

Global $sTempFile=@ScriptDir&'\~scriptomatic.tmp'
Global $aResult[0]

$wbemFlagReturnImmediately = 0x10
$wbemFlagForwardOnly = 0x20
$colItems = ""
$sComputer = "localhost"

$Output = ""
$sLvTitle = "Computer: " & $sComputer
$oWMIService = ObjGet("winmgmts:\\" & $sComputer & "\")
$colItems = $oWMIService.ExecQuery("SELECT * FROM CIM_VideoControllerResolution", "WQL", _
        $wbemFlagReturnImmediately + $wbemFlagForwardOnly)

If IsObj($colItems) Then
    $Output = $Output & "Caption: " & @TAB
    $Output = $Output & "Description: " & @TAB
    $Output = $Output & "HorizontalResolution: " & @TAB
    $Output = $Output & "MaxRefreshRate: " & @TAB
    $Output = $Output & "MinRefreshRate: " & @TAB
    $Output = $Output & "NumberOfColors: " & @TAB
    $Output = $Output & "RefreshRate: " & @TAB
    $Output = $Output & "ScanMode: " & @TAB
    $Output = $Output & "SettingID: " & @TAB
    $Output = $Output & "VerticalResolution: " & @CRLF
    For $objItem In $colItems
        $Output = $Output & $objItem.Caption & @TAB
        $Output = $Output & $objItem.Description & @TAB
        $Output = $Output & $objItem.HorizontalResolution & @TAB
        $Output = $Output & $objItem.MaxRefreshRate & @TAB
        $Output = $Output & $objItem.MinRefreshRate & @TAB
        $Output = $Output & $objItem.NumberOfColors & @TAB
        $Output = $Output & $objItem.RefreshRate & @TAB
        $Output = $Output & $objItem.ScanMode & @TAB
        $Output = $Output & $objItem.SettingID & @TAB
        $Output = $Output & $objItem.VerticalResolution & @CRLF
    Next
    $hTmp=FileOpen($sTempFile,2)
    FileWrite($hTmp,$Output)
    FileClose($hTmp)
    _FileReadToArray($sTempFile,$aResult,$FRTA_NOCOUNT, @TAB)
    _ArrayDisplay($aResult)
    FileDelete($sTempFile)
Else
    MsgBox(0, "WMI Output", "No WMI Objects Found for class: " & "CIM_VideoControllerResolution")
EndIf

no you have all posible resolution from VideoControllerResolution in a Array

1 person likes this

Share this post


Link to post
Share on other sites

Alright, I went to the scriptomatic and it worked alright, but I can only find a setting to get the current settings (found in winmgmts:\\localhost\ROOT\CIMV2\Win32_DisplayConfiguration) and not the highest possible settings on the monitor.

Any ideas?

Share this post


Link to post
Share on other sites

Sweet!. That actually helps a lot. Thanks.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now