Jump to content

Detect monitor maximum (native) resolution


Stilez
 Share

Recommended Posts

I wrote this code, which seems to work well, including in virtual machines. VM detection matters because

  • In a VM you probably need to specify a maximum valid resolution (as it can only check adapter values) and the refresh rate won't really be variable as it has to match the @DESKTOP rate.
  • In a non-VM you can usually use the maximum returned resolution (as the monitor is usually genuine hardware), but the refresh rate is best limited out of caution to ~ 85 - 100 Hz when automated.
The code looks for the largest 32 bit per pixel resolution since most people probably use 32 bit display settings and it's unusual to find an adapter that can't do 32 bits on max resolution if needed. It also ignores all resolutions below that which you're already using, and below 800 wide or high, and returns zero if you're already using max resolution. If you always want the max value returned, edit the lines "$min_width =" and "$min_height =" to zero or 800 x 600 or something.

There will usually be one monitor resolution that's maximum for both width and height. The parameters include a maximum width only - for simplicity if you define a max width, it automatically returns the maximum height supported by that width (if more than the minimum or current screen size).

Code related to detecting valid resolutions is by Rasim (). Code related to VM detection also included ("_CheckVM"), which I've posted elsewhere () and uses code by Fennek (link).

Dim $a[3]

#include <Math.au3>
#include <Array.au3>

; different parameters in a VM
If _CheckVM() = "" Then
    MsgBox(0,"","Did not detect VM." & @CRLF & @CRLF &"Checking for a larger resolution than your current one. Limits:" & @CRLF & @CRLF & "Refresh rate - up to 90 Hz")
    _GetMaxNativeResolution($a)
Else
    MsgBox(0,"","Detected VM." & @CRLF & @CRLF &"Checking for a larger resolution than your current one. Limits:" & @CRLF & @CRLF & "Width - ignoring anything over 1600" & @CRLF  & "Refresh rate - same as your current refresh rate (" & @DesktopRefresh & "Hz)")
    _GetMaxNativeResolution($a, 1600, -1)
EndIf

; results -> user
If @error Then
    MsgBox(0,"", "Cannot identify a larger ""maximum"" resolution - no valid larger 32bpp resolutions found.")
Else
    MsgBox(0,"", "Found one or more valid larger resolutions within the limits" & @CRLF & @CRLF &"Largest ""guaranteed"" resolution was " & $a[0] & " x " & $a[1] & " @ " & $a[2] & "Hz (32 bits per pixel)")
EndIf




; ------------------------------------ End main

; ------------------------------------  Start max resolution funcs


; Attempt to identify the maximum resolution for the main display.  Complicated by 
;    1) Virtual machines can report very large "valid resolutions" the user may not want
;       or refresh rates that are meaningless for a "screen" that's really just a window
;    2) high refresh rates can damage hardware
;
; $out[3] will be set to an array [width, height, resolution] for the highest valid 32 bit per pixel resolution found
; or 0 if no valid higher resolution could be found (eg already operating at max resolution)
;
;$max_width (optional) limits the resolutions which can be returned (eg in a VM one might set $max_width = 1440). 
; Default 0 = don't limit
; On a non-VM usually use the default 0 or a limit you know to be valid.
;
; $max_refresh (optional) sets a limit on refresh rate if >0, or forces current refresh rate matching if <0. 
; Default = 90 Hz.
; On a VM use $max_refresh = -1 to match the existing screen refresh rate.

Func _GetMaxNativeResolution(ByRef $out, $max_width = 0, $max_refresh = 90)
    Dim $DEVMODE, $DllRet, $enum = 0, $valid_res[1][4]
    Local Const $EDS_RAWMODE = 0x2
    
    $min_width = _Max(@DesktopWidth + 1, 800)
    $min_height = _Max(@DesktopHeight + 1, 800)
    If $max_width = 0 Then $max_width = 99999
    
    $res_count = 0
    
    ; Get valid resolutions. Code for detecting list of reported valid resolutions is by Rasim
    ; www.autoitscript.com/forum/topic/70679-optain-supported-resolutions-via-enumdisplaysettingsex-call

    $DEVMODE = DllStructCreate("char dmDeviceName[32];ushort dmSpecVersion;ushort dmDriverVersion;short dmSize;" & _
                               "ushort dmDriverExtra;dword dmFields;short dmOrientation;short dmPaperSize;short dmPaperLength;" & _
                               "short dmPaperWidth;short dmScale;short dmCopies;short dmDefaultSource;short dmPrintQuality;" & _
                               "short dmColor;short dmDuplex;short dmYResolution;short dmTTOption;short dmCollate;" & _
                               "byte dmFormName[32];dword dmBitsPerPel;int dmPelsWidth;dword dmPelsHeight;" & _
                               "dword dmDisplayFlags;dword dmDisplayFrequency")
        
    DllStructSetData($DEVMODE, "dmSize", DllStructGetSize($DEVMODE))
        
    Do
        $DllRet = DllCall("user32.dll", "int", "EnumDisplaySettingsEx", "ptr", 0, "dword", $enum, _
                          "ptr", DllStructGetPtr($DEVMODE), "dword", 0)
        $DllRet = $DllRet[0]
        $enum += 1
        
        $w = DllStructGetData($DEVMODE, "dmPelsWidth")          ; width
        $h = DllStructGetData($DEVMODE, "dmPelsHeight")         ; height
        $r = DllStructGetData($DEVMODE, "dmDisplayFrequency")   ; refresh rate
        $bpp = DllStructGetData($DEVMODE, "dmBitsPerPel")       ; bits per pixel
        If $bpp <> 32 Or $w < $min_width Or $w > $max_width Or $h < $min_height Then ContinueLoop
        If ($max_refresh < 0 And $r <> @DesktopRefresh) Or ($max_refresh > 0 And $r > $max_refresh) Then ContinueLoop

        ReDim $valid_res[$res_count + 1][4]

        $valid_res[$res_count][0] = $w
        $valid_res[$res_count][1] = $h
        $valid_res[$res_count][2] = $r
        ;$valid_res[$res_count][3] = $bpp       ; bits per pixel - not interested
        
        ; and create a sort key - ensure fixed width fields for sorting
        $valid_res[$res_count][3] = StringFormat("%06d",$w) & "-" & StringFormat("%06d",$h) & "-" & StringFormat("%03d",$r)
        $res_count += 1
        
    Until $DllRet = 0

    $DEVMODE = 0
    
    If $res_count = 0 Then
        $out = 0
        SetError(1)
        return 1
    Else
        ; Sort, then return the largest item (last entry) as a 1-dimension array.
        _ArraySort($valid_res,0,0,0,3)
        Dim $out[3] = [  $valid_res[$res_count - 1][0], $valid_res[$res_count - 1][1], $valid_res[$res_count - 1][2]  ]
        SetError(0)
        return 0
    EndIf
    
EndFunc   ;==>_GetMaxNativeResolution



; ------------------------------------  End max resolution funcs

; ------------------------------------  Start VM detection funcs (not strictly part of this script)



; Checks if we're in a VM. Returns "" if we aren't, or a string containing the diagnostic explanation if we are.

; Uses code by fennek, extra logic by Stilez
; www.secret-zone.net/showthread.php?3143-Detect-Vmware-VirtualBox-VirtualP-Autoit
; and
; www.autoitscript.com/forum/topic/131607-detect-running-in-virtual-machine

; Method: Checks for VM services/processes, hard drives, bios ID and motherboard ID
; Reports a VM only if hardware in * 2 or more different categories * are found
; Note - reason is, non-VMs might use virtual hardware or have the word "virtual" in some description
Func _CheckVM()
    $strComputer = '.'
    $objWMIService = ObjGet('winmgmts:\\' & $strComputer & '\root\cimv2')
    $vmhit_count = 0
    $vmhit_details = ""

    ; Check for VM management processes
    If ProcessExists("VBoxService.exe") Or ProcessExists("VBoxTray.exe") Or ProcessExists("VMwareTray.exe") Or ProcessExists("VMwareUser.exe")  Then _AddVMHit($vmhit_count, $vmhit_details, "RUNNING SOFTWARE", "Found a Vbox or VMware service or tray process")
 
    ; Check for VM devices
    If Not IsObj($objWMIService) Then
        msgbox(0,"","? WTF?")
        return ""
    EndIf
    
    ; Check for VM hard disks
    $colItems = $objWMIService.ExecQuery('SELECT * FROM Win32_DiskDrive', 'WQL', 0x10 + 0x20)
    If IsObj($colItems) Then
        For $objItem In $colItems
            $vReturn = $objItem.Model
            Select
                Case StringInStr($vReturn,"VBOX HARDDISK") 
                    _AddVMHit($vmhit_count, $vmhit_details, "DISKS", "Found device ""VBOX HARDDISK""")
                Case StringInStr($vReturn,"QEMU HARDDISK") 
                    _AddVMHit($vmhit_count, $vmhit_details, "DISKS", "Found device ""QEMU HARDDISK""")
                Case StringInStr($vReturn,"VMWARE VIRTUAL IDE HARD DRIVE") 
                    _AddVMHit($vmhit_count, $vmhit_details, "DISKS", "Found device ""VMWARE VIRTUAL IDE HARD DRIVE""")
                Case StringInStr($vReturn,"VMware Virtual S SCSI Disk Device") 
                    _AddVMHit($vmhit_count, $vmhit_details, "DISKS", "Found device ""VMware Virtual S SCSI Disk Device""")
            EndSelect
        Next
    EndIf
 
    ; Check for VM BIOS
    $colItems = $objWMIService.ExecQuery("SELECT * FROM Win32_BIOS", "WQL", 0x10 + 0x20)
    If IsObj($colItems) Then
            For $objItem In $colItems
                Select
                    Case StringInStr($objItem.BIOSVersion(0),"Vbox") 
                        _AddVMHit($vmhit_count, $vmhit_details, "BIOS", "Found Vbox BIOS version")
                    Case StringInStr($objItem.SMBIOSBIOSVersion,"virt") 
                        _AddVMHit($vmhit_count, $vmhit_details, "BIOS", "Found Vbox BIOS version")
                EndSelect
            Next
    EndIf

    ; Check for VM Motherboard/chipset
    $colItems = $objWMIService.ExecQuery("SELECT * FROM Win32_Baseboard", "WQL", 0x10 + 0x20)
    If IsObj($colItems) Then
        For $objItem In $colItems
            Select
                Case StringInStr($objItem.Name,"Base Board") And StringInStr($objItem.Product, "440BX Desktop Reference Platform") 
                    _AddVMHit($vmhit_count, $vmhit_details, "MOTHERBOARD", "Found VMware-style motherboard, ""440BX Desktop Reference Platform"" / Name=""Base Board""")
            EndSelect
        Next
    EndIf
 
    If $vmhit_count >= 2 Then
        Return $vmhit_details & @CRLF & @CRLF & "Hits in " & $vmhit_count & " of 4 hardware categories - probably a virtual machine."
    Else
        Return ""
    EndIf
    
EndFunc ;==>_CheckVM

; Notes a hardware hit, but doesn't increase the "category count" if we've already noted VM hardware in a given category
Func _AddVMHit(ByRef $vmhit_count, ByRef $vmhit_details, $this_hit_category, $this_hit_text)
    If StringInStr($vmhit_details, "In CATEGORY:" & $this_hit_category & ":") Then
        ; Already logged a hit in this category, just note the extra hit
        $vmhit_details &= " and " & $this_hit_text
    Else
        ; Category not logged yet - add it and the hit
        if $vmhit_details > "" Then $vmhit_details &= @CRLF
        $vmhit_details &= "In CATEGORY:" & $this_hit_category & ": " & $this_hit_text
        $vmhit_count += 1
    EndIf
EndFunc ;==>_AddVMHit
Edited by Stilez
Link to comment
Share on other sites

  • 1 year later...

Dim $a[3]

#include <Math.au3>
#include <Array.au3>

; different parameters in a VM
If _CheckVM() = "" Then
    MsgBox(0,"","Did not detect VM." & @CRLF & @CRLF &"Checking for a larger resolution than your current one. Limits:" & @CRLF & @CRLF & "Refresh rate - up to 90 Hz")
    _GetMaxNativeResolution($a)
Else
    MsgBox(0,"","Detected VM." & @CRLF & @CRLF &"Checking for a larger resolution than your current one. Limits:" & @CRLF & @CRLF & "Width - ignoring anything over 1600" & @CRLF & "Refresh rate - same as your current refresh rate (" & @DesktopRefresh & "Hz)")
    _GetMaxNativeResolution($a, 1600, -1)
EndIf

; results -> user
If @error Then
    MsgBox(0,"", "Cannot identify a larger ""maximum"" resolution - no valid larger 32bpp resolutions found.")
Else
    MsgBox(0,"", "Found one or more valid larger resolutions within the limits" & @CRLF & @CRLF &"Largest ""guaranteed"" resolution was " & $a[0] & " x " & $a[1] & " @ " & $a[2] & "Hz (32 bits per pixel)")
EndIf




; ------------------------------------ End main

; ------------------------------------ Start max resolution funcs


; Attempt to identify the maximum resolution for the main display. Complicated by
; 1) Virtual machines can report very large "valid resolutions" the user may not want
; or refresh rates that are meaningless for a "screen" that's really just a window
; 2) high refresh rates can damage hardware
;
; $out[3] will be set to an array [width, height, resolution] for the highest valid 32 bit per pixel resolution found
; or 0 if no valid higher resolution could be found (eg already operating at max resolution)
;
;$max_width (optional) limits the resolutions which can be returned (eg in a VM one might set $max_width = 1440).
; Default 0 = don't limit
; On a non-VM usually use the default 0 or a limit you know to be valid.
;
; $max_refresh (optional) sets a limit on refresh rate if >0, or forces current refresh rate matching if <0.
; Default = 90 Hz.
; On a VM use $max_refresh = -1 to match the existing screen refresh rate.

Func _GetMaxNativeResolution(ByRef $out, $max_width = 0, $max_refresh = 90)
    Dim $DEVMODE, $DllRet, $enum = 0, $valid_res[1][4]
    Local Const $EDS_RAWMODE = 0x2
    
    $min_width = _Max(@DesktopWidth + 1, 800)
    $min_height = _Max(@DesktopHeight + 1, 800)
    If $max_width = 0 Then $max_width = 99999
    
    $res_count = 0
    
    ; Get valid resolutions. Code for detecting list of reported valid resolutions is by Rasim
    ; www.autoitscript.com/forum/topic/70679-optain-supported-resolutions-via-enumdisplaysettingsex-call

    $DEVMODE = DllStructCreate("char dmDeviceName[32];ushort dmSpecVersion;ushort dmDriverVersion;short dmSize;" & _
                             "ushort dmDriverExtra;dword dmFields;short dmOrientation;short dmPaperSize;short dmPaperLength;" & _
                             "short dmPaperWidth;short dmScale;short dmCopies;short dmDefaultSource;short dmPrintQuality;" & _
                             "short dmColor;short dmDuplex;short dmYResolution;short dmTTOption;short dmCollate;" & _
                             "byte dmFormName[32];dword dmBitsPerPel;int dmPelsWidth;dword dmPelsHeight;" & _
                             "dword dmDisplayFlags;dword dmDisplayFrequency")
        
    DllStructSetData($DEVMODE, "dmSize", DllStructGetSize($DEVMODE))
        
    Do
        $DllRet = DllCall("user32.dll", "int", "EnumDisplaySettingsEx", "ptr", 0, "dword", $enum, _
                         "ptr", DllStructGetPtr($DEVMODE), "dword", 0)
        $DllRet = $DllRet[0]
        $enum += 1
        
        $w = DllStructGetData($DEVMODE, "dmPelsWidth")          ; width
        $h = DllStructGetData($DEVMODE, "dmPelsHeight")         ; height
        $r = DllStructGetData($DEVMODE, "dmDisplayFrequency")   ; refresh rate
        $bpp = DllStructGetData($DEVMODE, "dmBitsPerPel")       ; bits per pixel
        If $bpp <> 32 Or $w < $min_width Or $w > $max_width Or $h < $min_height Then ContinueLoop
        If ($max_refresh < 0 And $r <> @DesktopRefresh) Or ($max_refresh > 0 And $r > $max_refresh) Then ContinueLoop

        ReDim $valid_res[$res_count + 1][4]

        $valid_res[$res_count][0] = $w
        $valid_res[$res_count][1] = $h
        $valid_res[$res_count][2] = $r
        ;$valid_res[$res_count][3] = $bpp       ; bits per pixel - not interested
        
        ; and create a sort key - ensure fixed width fields for sorting
        $valid_res[$res_count][3] = StringFormat("%06d",$w) & "-" & StringFormat("%06d",$h) & "-" & StringFormat("%03d",$r)
        $res_count += 1
        
    Until $DllRet = 0

    $DEVMODE = 0
    
    If $res_count = 0 Then
        $out = 0
        SetError(1)
        return 1
    Else
        ; Sort, then return the largest item (last entry) as a 1-dimension array.
        _ArraySort($valid_res,0,0,0,3)
        Dim $out[3] = [ $valid_res[$res_count - 1][0], $valid_res[$res_count - 1][1], $valid_res[$res_count - 1][2] ]
        SetError(0)
        return 0
    EndIf
    
EndFunc ;==>_GetMaxNativeResolution



; ------------------------------------ End max resolution funcs

; ------------------------------------ Start VM detection funcs (not strictly part of this script)



; Checks if we're in a VM. Returns "" if we aren't, or a string containing the diagnostic explanation if we are.

; Uses code by fennek, extra logic by Stilez
; www.secret-zone.net/showthread.php?3143-Detect-Vmware-VirtualBox-VirtualP-Autoit
; and
; www.autoitscript.com/forum/topic/131607-detect-running-in-virtual-machine

; Method: Checks for VM services/processes, hard drives, bios ID and motherboard ID
; Reports a VM only if hardware in * 2 or more different categories * are found
; Note - reason is, non-VMs might use virtual hardware or have the word "virtual" in some description
Func _CheckVM()
    $strComputer = '.'
    $objWMIService = ObjGet('winmgmts:\\' & $strComputer & '\root\cimv2')
    $vmhit_count = 0
    $vmhit_details = ""

    ; Check for VM management processes
    If ProcessExists("VBoxService.exe") Or ProcessExists("VBoxTray.exe") Or ProcessExists("VMwareTray.exe") Or ProcessExists("VMwareUser.exe") Then _AddVMHit($vmhit_count, $vmhit_details, "RUNNING SOFTWARE", "Found a Vbox or VMware service or tray process")

    ; Check for VM devices
    If Not IsObj($objWMIService) Then
        msgbox(0,"","? WTF?")
        return ""
    EndIf
    
    ; Check for VM hard disks
    $colItems = $objWMIService.ExecQuery('SELECT * FROM Win32_DiskDrive', 'WQL', 0x10 + 0x20)
    If IsObj($colItems) Then
        For $objItem In $colItems
            $vReturn = $objItem.Model
            Select
                Case StringInStr($vReturn,"VBOX HARDDISK")
                    _AddVMHit($vmhit_count, $vmhit_details, "DISKS", "Found device ""VBOX HARDDISK""")
                Case StringInStr($vReturn,"QEMU HARDDISK")
                    _AddVMHit($vmhit_count, $vmhit_details, "DISKS", "Found device ""QEMU HARDDISK""")
                Case StringInStr($vReturn,"VMWARE VIRTUAL IDE HARD DRIVE")
                    _AddVMHit($vmhit_count, $vmhit_details, "DISKS", "Found device ""VMWARE VIRTUAL IDE HARD DRIVE""")
                Case StringInStr($vReturn,"VMware Virtual S SCSI Disk Device")
                    _AddVMHit($vmhit_count, $vmhit_details, "DISKS", "Found device ""VMware Virtual S SCSI Disk Device""")
            EndSelect
        Next
    EndIf

    ; Check for VM BIOS
    $colItems = $objWMIService.ExecQuery("SELECT * FROM Win32_BIOS", "WQL", 0x10 + 0x20)
    If IsObj($colItems) Then
            For $objItem In $colItems
                Select
                    Case StringInStr($objItem.BIOSVersion(0),"Vbox")
                        _AddVMHit($vmhit_count, $vmhit_details, "BIOS", "Found Vbox BIOS version")
                    Case StringInStr($objItem.SMBIOSBIOSVersion,"virt")
                        _AddVMHit($vmhit_count, $vmhit_details, "BIOS", "Found Vbox BIOS version")
                EndSelect
            Next
    EndIf

    ; Check for VM Motherboard/chipset
    $colItems = $objWMIService.ExecQuery("SELECT * FROM Win32_Baseboard", "WQL", 0x10 + 0x20)
    If IsObj($colItems) Then
        For $objItem In $colItems
            Select
                Case StringInStr($objItem.Name,"Base Board") And StringInStr($objItem.Product, "440BX Desktop Reference Platform")
                    _AddVMHit($vmhit_count, $vmhit_details, "MOTHERBOARD", "Found VMware-style motherboard, ""440BX Desktop Reference Platform"" / Name=""Base Board""")
            EndSelect
        Next
    EndIf

    If $vmhit_count >= 2 Then
        Return $vmhit_details & @CRLF & @CRLF & "Hits in " & $vmhit_count & " of 4 hardware categories - probably a virtual machine."
    Else
        Return ""
    EndIf
    
EndFunc ;==>_CheckVM

; Notes a hardware hit, but doesn't increase the "category count" if we've already noted VM hardware in a given category
Func _AddVMHit(ByRef $vmhit_count, ByRef $vmhit_details, $this_hit_category, $this_hit_text)
    If StringInStr($vmhit_details, "In CATEGORY:" & $this_hit_category & ":") Then
        ; Already logged a hit in this category, just note the extra hit
        $vmhit_details &= " and " & $this_hit_text
    Else
        ; Category not logged yet - add it and the hit
        if $vmhit_details > "" Then $vmhit_details &= @CRLF
        $vmhit_details &= "In CATEGORY:" & $this_hit_category & ": " & $this_hit_text
        $vmhit_count += 1
    EndIf
EndFunc ;==>_AddVMHit

I'd really like to know how to get this to retrieve max resolutions for more than one monitor (typically dual). :mellow: Sorry to ask point blank, but I really haven't the foggiest on DllCalls and DllStructGetData type of stuff... :
Link to comment
Share on other sites

I got something that sort of works, but not in every situation (doesn't always find both monitors - depending on video card it seems). This is from some small changes to KaFu's _Enum_Possible_Resolutions func from his utility (lines 56-67 & 131 below), combined with two functions from

#include
#region DllOpen_PostProcessor START
Global $h_DLL_msvcrt = DllOpen("msvcrt.dll")
Global $h_DLL_Kernel32 = DllOpen("kernel32.dll")
Global $h_DLL_user32 = DllOpen("user32.dll")
Global $h_DLL_GDI32 = DllOpen("gdi32.dll")
Global $h_DLL_ComCTL32 = DllOpen("comctl32.dll")
Global $h_DLL_OLE32 = DllOpen("ole32.dll")
Global $h_DLL_OLEAut32 = DllOpen("oleaut32.dll")
Global $h_DLL_Crypt32 = DllOpen("Crypt32.dll")
Global $h_DLL_NTDll = DllOpen("ntdll.dll")
#region DllOpen_PostProcessor END

Global Const $DMDO_DEFAULT = 0
Global Const $DMDO_90 = 1
Global Const $DMDO_180 = 2
Global Const $DMDO_270 = 3

Global Const $SMTO_ABORTIFHUNG = 0x0002
Global Const $MSG_TIMEOUT = 250

Global $b_Res_Orientation_Rotation_Supported = False
Global $i_Initial_Width, $i_Initial_Heigth


Global Const $ENUM_CURRENT_SETTINGS = -1
Global Const $ENUM_REGISTRY_SETTINGS = -2

Global $aSupportedResolutions[1][6]
Global $sCurrent_Setting_ColorDepth, $sCurrent_Setting_DesktopWidth, $sCurrent_Setting_DesktopHeigth, $sCurrent_Setting_MonitorFrequency
Global $sCombo_Resolution, $sCombo_ColorDepth, $sCombo_ColorDepth_Default, $sCombo_MonitorFreq

Global $hGUI_HRC_Main
Global $c_Hyperlink_URL_homepage, $c_Hyperlink_CC, $c_Hyperlink_Donate_Picture
Global $nCombo_Number, $nCombo_Number_Save, $nButton_Refresh
Global $nCombo_Res[10], $nCombo_Res_Save[10], $nCombo_Res_State[10], $nCombo_Fre[10], $nCombo_Col[10], $nButton_Apl[10]
Global $c_checkbox_Rawmode, $c_label_Rawmode
Global $c_checkbox_Rotatedmode, $c_label_Rotatedmode
;Global $c_checkbox_Largemode, $c_label_Largemode
Global $nCombo_Orientation

#include
Global $pEnumProc_ArraySortClib_Mem1 = _MemVirtualAlloc(0, 64, $MEM_COMMIT, $PAGE_EXECUTE_READWRITE) ; needed for _ArraySortClib()
Global $pEnumProc_ArraySortClib_Mem2 = _MemVirtualAlloc(0, 64, $MEM_COMMIT, $PAGE_EXECUTE_READWRITE) ; needed for _ArraySortClib()
Global $pEnumProc_ArraySortClib_Mem3 = _MemVirtualAlloc(0, 36, $MEM_COMMIT, $PAGE_EXECUTE_READWRITE) ; needed for _ArraySortClib()


Global Const $_tag_POINTL = "long x;long y"
Global Const $_tag_DEVMODE = "char dmDeviceName[32];ushort dmSpecVersion;ushort dmDriverVersion;short dmSize;" & _
"ushort dmDriverExtra;dword dmFields;" & $_tag_POINTL & ";dword dmDisplayOrientation;dword dmDisplayFixedOutput;" & _
"short dmColor;short dmDuplex;short dmYResolution;short dmTTOption;short dmCollate;" & _
"byte dmFormName[32];ushort LogPixels;dword dmBitsPerPel;int dmPelsWidth;dword dmPelsHeight;" & _
"dword dmDisplayFlags;dword dmDisplayFrequency"

;Modified -------
Global $s_Display

$Info = _DisplayKeySettings("",-1)
;_ArrayDisplay($Info)

For $Loop = 1 to $Info[0][0]
$CurDisplay = $Info[$Loop][1]
_Enum_Possible_Resolutions($CurDisplay)
_ArrayDisplay($aSupportedResolutions,$CurDisplay)
Next

Exit
; ---------------------

;Global $aSupportedResolutions[0]

;_Enum_Possible_Resolutions()


; =================================================
; Get all possible resolutions from WinAPI
; =================================================
Func _Enum_Possible_Resolutions($s_Display)

#cs
To ensure that the DEVMODE structure passed to ChangeDisplaySettingsEx is valid and contains only
values supported by the display driver, use the DEVMODE returned by the EnumDisplaySettings function.
When adding a display monitor to a multiple-monitor system programmatically, set DEVMODE.dmFields to
DM_POSITION and specify a position (in DEVMODE.dmPosition) for the monitor you are adding that is
adjacent to at least one pixel of the display area of an existing monitor. To detach the monitor,
set DEVMODE.dmFields to DM_POSITION but set DEVMODE.dmPelsWidth and DEVMODE.dmPelsHeight to zero.
For more information, see Multiple Display Monitors.
#ce

Local $DEVMODE = DllStructCreate($_tag_DEVMODE)
DllStructSetData($DEVMODE, "dmSize", DllStructGetSize($DEVMODE))

Local $iFlags = 0
Local Const $EDS_RAWMODE = 0x00000002
; If set, the function will return all graphics modes reported by the adapter driver, regardless of monitor capabilities. Otherwise, it will only return modes that are compatible with current monitors.
Local Const $EDS_ROTATEDMODE = 0x00000004
; If set, the function will return graphics modes in all orientations. Otherwise, it will only return modes that have the same orientation as the one currently set for the requested display.
;~ If Not $is_Orientation_Rotation_Supported Then
;~ If IniRead(@ScriptDir & "\HRC.ini", 'Settings', 'RAWMODE', 4) = 1 Then $iFlags = BitOR($iFlags, $EDS_RAWMODE)
;~ If IniRead(@ScriptDir & "\HRC.ini", 'Settings', 'ROTATEDMODE', 4) = 1 Then $iFlags = BitOR($iFlags, $EDS_ROTATEDMODE)
;~ EndIf

#cs
Local $b_Largemode = False
If IniRead(@ScriptDir & "\HRC.ini", 'Settings', 'Largemode', 4) = 1 Then $b_Largemode = True
#ce

; Get current graphic settings
; =================================================
;~ $DllRet = DllCall($h_DLL_user32, "int", "EnumDisplaySettingsEx", "ptr", 0, "dword", $ENUM_CURRENT_SETTINGS, "ptr", DllStructGetPtr($DEVMODE), "dword", 0)
;~ If $DllRet[0] = 0 Then
;~ ConsoleWrite(@CRLF & "From reg" & @CRLF)
;~ $DllRet = DllCall($h_DLL_user32, "int", "EnumDisplaySettingsEx", "ptr", 0, "dword", $ENUM_REGISTRY_SETTINGS, "ptr", DllStructGetPtr($DEVMODE), "dword", 0)
;~ EndIf

$sCurrent_Setting_ColorDepth = DllStructGetData($DEVMODE, "dmBitsPerPel")
$sCurrent_Setting_DesktopWidth = DllStructGetData($DEVMODE, "dmPelsWidth")
$sCurrent_Setting_DesktopHeigth = DllStructGetData($DEVMODE, "dmPelsHeight")
$sCurrent_Setting_MonitorFrequency = DllStructGetData($DEVMODE, "dmDisplayFrequency")

If Not $i_Initial_Width Then $i_Initial_Width = $sCurrent_Setting_DesktopWidth
If Not $i_Initial_Heigth Then $i_Initial_Heigth = $sCurrent_Setting_DesktopHeigth

$ENUM_ALL_SETTINGS = 0
$i = 0
ReDim $aSupportedResolutions[1000][6]

Local $i_current_Width, $i_current_Height

Do
$DllRet = DllCall($h_DLL_user32, "int", "EnumDisplaySettingsEx", "str", $s_Display, "dword", $ENUM_ALL_SETTINGS, "ptr", DllStructGetPtr($DEVMODE), "dword", $iFlags)
$DllRet = $DllRet[0]

$i_current_Width = DllStructGetData($DEVMODE, "dmPelsWidth")
$i_current_Height = DllStructGetData($DEVMODE, "dmPelsHeight")

;~ If $is_Orientation_Rotation_Supported Then
;~ If Not $b_Res_Orientation_Rotation_Supported Then
;~ If DllStructGetData($DEVMODE, "dmDisplayOrientation") Then $b_Res_Orientation_Rotation_Supported = True
;~ EndIf
;~ EndIf

If Not BitAND($iFlags, $EDS_ROTATEDMODE) Then
If $i_current_Height > $i_current_Width Then
$ENUM_ALL_SETTINGS += 1
ContinueLoop
EndIf
EndIf

#cs
If Not $b_Largemode Then
If $b_Res_Orientation_Rotation_Supported Then
If ($i_current_Width > $i_Initial_Width And $i_current_Width > $i_Initial_Heigth) Or ($i_current_Height > $i_Initial_Heigth And $i_current_Height > $i_Initial_Width) Then
$ENUM_ALL_SETTINGS += 1
ContinueLoop
EndIf
Else
If $i_current_Width > $i_Initial_Width Or $i_current_Height > $i_Initial_Heigth Then
$ENUM_ALL_SETTINGS += 1
ContinueLoop
EndIf
EndIf
EndIf
#ce

$aSupportedResolutions[$i][0] = $i_current_Width
$aSupportedResolutions[$i][1] = $i_current_Height
$aSupportedResolutions[$i][2] = DllStructGetData($DEVMODE, "dmBitsPerPel") ; Color Bits
$aSupportedResolutions[$i][4] = DllStructGetData($DEVMODE, "dmDisplayFrequency") ; Frequency

#cs
ConsoleWrite(DllStructGetData($DEVMODE, "dmPelsWidth") & @CRLF)
ConsoleWrite(DllStructGetData($DEVMODE, "dmPelsHeight") & @CRLF)
ConsoleWrite(DllStructGetData($DEVMODE, "dmBitsPerPel") & @CRLF)
ConsoleWrite(DllStructGetData($DEVMODE, "dmDisplayFrequency") & @CRLF)
ConsoleWrite(DllStructGetData($DEVMODE, "dmDisplayOrientation") & @CRLF)
ConsoleWrite(@CRLF)
#ce

; Color Names
Switch $aSupportedResolutions[$i][2]
Case 1
$aSupportedResolutions[$i][3] = "1 Bit - 2 colors"
Case 2
$aSupportedResolutions[$i][3] = "2 Bit - 4 colors"
Case 3
$aSupportedResolutions[$i][3] = "3 Bit - 8 colors"
Case 4
$aSupportedResolutions[$i][3] = "4 Bit - 16 colors"
Case 5
$aSupportedResolutions[$i][3] = "5 Bit - 32 colors"
Case 6
$aSupportedResolutions[$i][3] = "6 Bit - 64 colors"
Case 8
$aSupportedResolutions[$i][3] = "8 Bit - 256 colors"
Case 12
$aSupportedResolutions[$i][3] = "12 Bit - 4.096 colors"
Case 16
$aSupportedResolutions[$i][3] = "16 Bit - 65k colors"
Case 32
$aSupportedResolutions[$i][3] = "32 Bit - 4 billion colors"
EndSwitch

; Sort Column
$aSupportedResolutions[$i][5] = StringFormat("%04i", $aSupportedResolutions[$i][0]) & StringFormat("%04i", $aSupportedResolutions[$i][1]) & StringFormat("%02i", $aSupportedResolutions[$i][2]) & StringFormat("%03i", $aSupportedResolutions[$i][4])

If $DllRet <> 0 Then
$ENUM_ALL_SETTINGS += 1
$i += 1
If Not Mod(1000, $i) Then ReDim $aSupportedResolutions[UBound($aSupportedResolutions) + 1000][6]
EndIf

Until $DllRet = 0

ReDim $aSupportedResolutions[$i + 1][6]
; ConsoleWrite(TimerInit() & @TAB & $i + 1 & @TAB & $ENUM_ALL_SETTINGS & @CRLF)

$DEVMODE = 0

_ArraySortClib($aSupportedResolutions, 0, True, 0, 0, 5)

; =================================================
; Get Resolutions END
; =================================================

$sCombo_Resolution = ""
For $i = 0 To UBound($aSupportedResolutions) - 1
If Not StringInStr($sCombo_Resolution, $aSupportedResolutions[$i][0] & " x " & $aSupportedResolutions[$i][1]) Then $sCombo_Resolution &= "|" & $aSupportedResolutions[$i][0] & " x " & $aSupportedResolutions[$i][1]
Next
$sCombo_ColorDepth = ""
$sCombo_ColorDepth_Default = ""
For $i = 0 To UBound($aSupportedResolutions) - 1
If StringInStr($sCurrent_Setting_DesktopWidth & " x " & $sCurrent_Setting_DesktopHeigth, $aSupportedResolutions[$i][0] & " x " & $aSupportedResolutions[$i][1]) And Not StringInStr($sCombo_ColorDepth, $aSupportedResolutions[$i][3]) Then $sCombo_ColorDepth &= "|" & $aSupportedResolutions[$i][3]
If $aSupportedResolutions[$i][2] = $sCurrent_Setting_ColorDepth Then $sCombo_ColorDepth_Default = $aSupportedResolutions[$i][3]
Next
$sCombo_MonitorFreq = ""
For $i = 0 To UBound($aSupportedResolutions) - 1
If $sCurrent_Setting_DesktopWidth & " x " & $sCurrent_Setting_DesktopHeigth = $aSupportedResolutions[$i][0] & " x " & $aSupportedResolutions[$i][1] Then
If Not StringInStr($sCombo_MonitorFreq, $aSupportedResolutions[$i][4]) Then $sCombo_MonitorFreq &= "|" & $aSupportedResolutions[$i][4] & " Hertz"
EndIf
Next

$nCombo_Res[0] = IniRead(@ScriptDir & "\HRC.ini", 'Settings', 'NumberOfHotKeyBoxes', 2) + 1

EndFunc ;==>_Enum_Possible_Resolutions

; http://www.autoitscript.com/forum/index.php?showtopic=63525&view=findpost&p=474072
;===============================================================================
; Function Name: _ArraySortClib() v4
; Description: Sort 1D/2D array using qsort() from C runtime library
; Syntax:
; Parameter(s): $Array - the array to be sorted, ByRef
; $iMode - sort mode, can be one of the following:
; 0 = numerical, using double precision float compare
; 1 = string sort, case insensitive (default)
; 2 = string sort, case sensitive
; 3 = word sort, case insensitive - compatible with AutoIt's native compare
; $fDescend - sort direction. True = descending, False = ascending (default)
; $iStart - index of starting element (default 0 = $array[0])
; $iEnd - index of ending element (default 0 = Ubound($array)-1)
; $iColumn - index of column to sort by (default 0 = first column)
; $iStrMax - max string length of each array element to compare (default 4095 chars)
; Requirement(s): msvcrt.dll (shipped with Windows since Win98 at least), 32-bit version of AutoIt
; Return Value(s): Success = Returns 1
; Failure = Returns 0 and sets error:
; @error 1 = invalid array
; @error 2 = invalid param
; @error 3 = dll error
; @error 64 = 64-bit AutoIt unsupported
; Author(s): Siao
; Modification(s): KaFu, added three global _MemVirtualAlloc() calls to top of script to prevent DEP Errors:
;
; Global $pEnumProc_ArraySortClib_Mem1 = _MemVirtualAlloc(0, 64, $MEM_COMMIT, $PAGE_EXECUTE_READWRITE) ; needed for _ArraySortClib()
; Global $pEnumProc_ArraySortClib_Mem2 = _MemVirtualAlloc(0, 64, $MEM_COMMIT, $PAGE_EXECUTE_READWRITE) ; needed for _ArraySortClib()
; Global $pEnumProc_ArraySortClib_Mem3 = _MemVirtualAlloc(0, 36, $MEM_COMMIT, $PAGE_EXECUTE_READWRITE) ; needed for _ArraySortClib()
;
;===============================================================================

Func _ArraySortClib(ByRef $array, $iMode = 1, $fDescend = False, $iStart = 0, $iEnd = 0, $iColumn = 0, $iStrMax = 4095)
If @AutoItX64 Then Return SetError(64, 0, 0)
Local $iArrayDims = UBound($array, 0)
If @error Or $iArrayDims > 2 Then Return SetError(1, 0, 0)
Local $iArraySize = UBound($array, 1), $iColumnMax = UBound($array, 2)
If $iArraySize < 2 Then Return SetError(1, 0, 0)
If $iEnd < 1 Or $iEnd > $iArraySize - 1 Then $iEnd = $iArraySize - 1
If ($iEnd - $iStart < 2) Then Return SetError(2, 0, 0)
If $iArrayDims = 2 And ($iColumnMax - $iColumn < 0) Then Return SetError(2, 0, 0)
If $iStrMax < 1 Then Return SetError(2, 0, 0)
Local $i, $j, $iCount = $iEnd - $iStart + 1, $fNumeric, $aRet, $sZero = ChrW(0), $sStrCmp, $sBufType = 'byte[', $tSource, $tIndex, $tFloatCmp

Local $tEnumProc = DllStructCreate('byte[64]', $pEnumProc_ArraySortClib_Mem1)
Local $tCmpWrap = DllStructCreate('byte[64]', $pEnumProc_ArraySortClib_Mem2)

If $h_DLL_msvcrt = -1 Then Return SetError(3, 0, 0)

;; initialize compare proc
Switch $iMode
Case 0
$fNumeric = True
$tFloatCmp = DllStructCreate('byte[36]', $pEnumProc_ArraySortClib_Mem3)
DllStructSetData($tFloatCmp, 1, '0x8B4C24048B542408DD01DC1ADFE0F6C440750D80E441740433C048C333C040C333C0C3')
DllStructSetData($tCmpWrap, 1, '0xBA' & Hex(Binary(DllStructGetPtr($tFloatCmp)), 8) & '8B4424088B4C2404FF30FF31FFD283C408C3')
DllStructSetData($tEnumProc, 1, '0x8B7424048B7C24088B4C240C8B442410893789470483C60883C708404975F1C21000')
Case 1, 2
$sStrCmp = "_strcmpi" ;case insensitive
If $iMode = 2 Then $sStrCmp = "strcmp" ;case sensitive
$aRet = DllCall($h_DLL_Kernel32, 'ptr', 'GetModuleHandle', 'str', 'msvcrt.dll')
$aRet = DllCall($h_DLL_Kernel32, 'ptr', 'GetProcAddress', 'ptr', $aRet[0], 'str', $sStrCmp)
;If $aRet[0] = 0 Then Return SetError(3, 0, 0 * DllClose($h_DLL_msvcrt))
If $aRet[0] = 0 Then Return SetError(3, 0, 1)
DllStructSetData($tCmpWrap, 1, '0xBA' & Hex(Binary($aRet[0]), 8) & '8B4424088B4C2404FF30FF31FFD283C408C3')
DllStructSetData($tEnumProc, 1, '0x8B7424048B7C24088B4C240C8B542410893789570483C7088A064684C075F9424975EDC21000')
Case 3
$sBufType = 'wchar['
$aRet = DllCall($h_DLL_Kernel32, 'ptr', 'GetModuleHandle', 'str', 'kernel32.dll')
$aRet = DllCall($h_DLL_Kernel32, 'ptr', 'GetProcAddress', 'ptr', $aRet[0], 'str', 'CompareStringW')
;If $aRet[0] = 0 Then Return SetError(3, 0, 0 * DllClose($h_DLL_msvcrt))
If $aRet[0] = 0 Then Return SetError(3, 0, 1)
DllStructSetData($tCmpWrap, 1, '0xBA' & Hex(Binary($aRet[0]), 8) & '8B4424088B4C24046AFFFF306AFFFF3168000000006800040000FFD283E802C3')
DllStructSetData($tEnumProc, 1, '0x8B7424048B7C24088B4C240C8B542410893789570483C7080FB70683C60285C075F6424975EAC21000')
Case Else

Return SetError(2, 0, 0)
EndSwitch
;; write data to memory
If $fNumeric Then
$tSource = DllStructCreate('double[' & $iCount & ']')
If $iArrayDims = 1 Then
For $i = 1 To $iCount
DllStructSetData($tSource, 1, $array[$iStart + $i - 1], $i)
Next
Else
For $i = 1 To $iCount
DllStructSetData($tSource, 1, $array[$iStart + $i - 1][$iColumn], $i)
Next
EndIf
Else
Local $sMem = ""
If $iArrayDims = 1 Then
For $i = $iStart To $iEnd
$sMem &= StringLeft($array[$i], $iStrMax) & $sZero
Next
Else
For $i = $iStart To $iEnd
$sMem &= StringLeft($array[$i][$iColumn], $iStrMax) & $sZero
Next
EndIf
$tSource = DllStructCreate($sBufType & StringLen($sMem) + 1 & ']')
DllStructSetData($tSource, 1, $sMem)
$sMem = ""
EndIf
;; index data
$tIndex = DllStructCreate('int[' & $iCount * 2 & ']')
DllCall($h_DLL_user32, 'uint', 'CallWindowProc', 'ptr', DllStructGetPtr($tEnumProc), 'ptr', DllStructGetPtr($tSource), 'ptr', DllStructGetPtr($tIndex), 'int', $iCount, 'int', $iStart)
;; sort
DllCall($h_DLL_msvcrt, 'none:cdecl', 'qsort', 'ptr', DllStructGetPtr($tIndex), 'int', $iCount, 'int', 8, 'ptr', DllStructGetPtr($tCmpWrap))
;DllClose($h_DLL_msvcrt)
;; rearrange the array by sorted index
Local $aTmp = $array, $iRef
If $iArrayDims = 1 Then ; 1D
If $fDescend Then
For $i = 0 To $iCount - 1
$iRef = DllStructGetData($tIndex, 1, $i * 2 + 2)
$array[$iEnd - $i] = $aTmp[$iRef]
Next
Else ; ascending
For $i = $iStart To $iEnd
$iRef = DllStructGetData($tIndex, 1, ($i - $iStart) * 2 + 2)
$array[$i] = $aTmp[$iRef]
Next
EndIf
Else ; 2D
If $fDescend Then
For $i = 0 To $iCount - 1
$iRef = DllStructGetData($tIndex, 1, $i * 2 + 2)
For $j = 0 To $iColumnMax - 1
$array[$iEnd - $i][$j] = $aTmp[$iRef][$j]
Next
Next
Else ; ascending
For $i = $iStart To $iEnd
$iRef = DllStructGetData($tIndex, 1, ($i - $iStart) * 2 + 2)
For $j = 0 To $iColumnMax - 1
$array[$i][$j] = $aTmp[$iRef][$j]
Next
Next
EndIf
EndIf
Return 1
EndFunc ;==>_ArraySortClib


Func _NumberAndNameMonitors()
Local $dev = -1, $id = 0, $msg_ = "", $EnumDisplays, $StateFlag
Dim $NumberAndName[2][6]
Local $DISPLAY_DEVICE = DllStructCreate("int;char[32];char[128];int;char[128];char[128]")
DllStructSetData($DISPLAY_DEVICE, 1, DllStructGetSize($DISPLAY_DEVICE))
Dim $dll = "user32.dll"
Do
$dev += 1
$EnumDisplays = DllCall($dll, "int", "EnumDisplayDevices", "ptr", 0, "int", $dev, "ptr", DllStructGetPtr($DISPLAY_DEVICE), "int", 1)
If $EnumDisplays[0] <> 0 Then
ReDim $NumberAndName[$dev + 2][6]
$NumberAndName[$dev + 1][1] = DllStructGetData($DISPLAY_DEVICE, 2) ;device Name
$NumberAndName[$dev + 1][2] = DllStructGetData($DISPLAY_DEVICE, 3) ;device or display description
$NumberAndName[$dev + 1][3] = Hex(DllStructGetData($DISPLAY_DEVICE, 4)) ;all flags (value in HEX)
$NumberAndName[$dev + 1][4] = DllStructGetData($DISPLAY_DEVICE, 6) ;registry key of the device
$NumberAndName[$dev + 1][5] = DllStructGetData($DISPLAY_DEVICE, 5) ;hardware interface name
EndIf

If $EnumDisplays[0] > 0 And StringMid($NumberAndName[$dev + 1][1],12,1) = "V" Then
;MsgBox(0,"test",$NumberAndName[$dev + 1][1] & " is virtual")
_ArrayDelete($NumberAndName,$dev + 1)
$EnumDisplays[0] -= 1
EndIf

Until $EnumDisplays[0] = 0
$NumberAndName[0][0] += $dev
Return $NumberAndName
EndFunc ;==>_NumberAndNameMonitors

Func _DisplayKeySettings($MonName, $Opt = -1)
Local Const $DISPLAY_DEVICE_MIRRORING_DRIVER = 0x00000008
Dim $KeySettings[1][10], $i, $Dn = 0, $res
If Not IsArray($MonName) Then $MonName = _NumberAndNameMonitors()
Local $DEVMODE = DllStructCreate("char[32];short[4];int[5];short[5];byte[32];short;int[6]")
DllStructSetData($DEVMODE, 2, DllStructGetSize($DEVMODE), 3)
For $i = 1 To $MonName[0][0]
If ($MonName[$i][3] <> $DISPLAY_DEVICE_MIRRORING_DRIVER) Then
$Dn += 1
$res = DllCall("user32.dll", "int", "EnumDisplaySettings", "str", $MonName[$i][1], "int", $Opt, "ptr", DllStructGetPtr($DEVMODE))
If $res[0] = 0 Then _
$res = DllCall("user32.dll", "int", "EnumDisplaySettings", "str", $MonName[$i][1], "int", Mod($Opt, 2) - 1, "ptr", DllStructGetPtr($DEVMODE))
ReDim $KeySettings[1 + $Dn][10]
$KeySettings[$Dn][0] = $MonName[$i][3] ;flags
$KeySettings[$Dn][1] = $MonName[$i][1] ;name
$KeySettings[$Dn][2] = DllStructGetData($DEVMODE, 3, 2) ;up left desktop position coord X
$KeySettings[$Dn][3] = DllStructGetData($DEVMODE, 3, 3) ;up left desktop position coord Y
$KeySettings[$Dn][4] = DllStructGetData($DEVMODE, 7, 2) ;Width (resolution)
$KeySettings[$Dn][5] = DllStructGetData($DEVMODE, 7, 3) ;Heigth (resolution)
$KeySettings[$Dn][6] = DllStructGetData($DEVMODE, 7, 1) ;Bpp color (resolution)
$KeySettings[$Dn][7] = DllStructGetData($DEVMODE, 7, 5) ;Screen Refresh(resolution)
$KeySettings[$Dn][8] = DllStructGetData($DEVMODE, 3, 4) ;Display Orientation
$KeySettings[$Dn][9] = DllStructGetData($DEVMODE, 3, 5) ;fixed output
EndIf
Next
$KeySettings[0][0] = $Dn
Return $KeySettings
EndFunc ;==>_DisplayKeySettings

The WMI method seems more reliable at finding different displays, but this only pulls current resolution, not max:

;Info on data types here: http://msdn.microsoft.com/en-us/library/windows/desktop/aa394122%28v=vs.85%29.aspx
#include <file.au3>
#include <array.au3>


Global $itdid, $objWMIService, $colItems, $sWMIService, $sName, $sModel, $uuItem, $objSWbemObject, $strName, $strVersion, $strWMIQuery, $objItem, $uiDitem
;$itdid = RegRead ( "HKEY_LOCAL_MACHINE\SOFTWARE\Intel\PIcon\AMTData", "System UUID" )


;~ $sWMIService = "winmgmts:\\" & @ComputerName & "\root\CIMV2"
;~ $objWMIService = ObjGet($sWMIService)
$strComputer = "."
$objWMIService = ObjGet("winmgmts:{impersonationLevel=impersonate}!\\" & $strComputer & "\root\cimv2")

ShellExecute("notepad.exe")
WinWaitActive("Untitled - Notepad")
Sleep(100)
SendKeepActive("Untitled - Notepad")

If IsObj($objWMIService) Then

$colItems = $objWMIService.ExecQuery("SELECT * FROM Win32_DesktopMonitor"); where DeviceID = DesktopMonitor1")

If IsObj($colItems) Then
For $oItem In $colItems
$sName = $oItem.Name
$sMonitorType = $oItem.MonitorType
$sMonitorManufacturer = $oItem.MonitorManufacturer
$sPixelsPerXLogicalInch = $oItem.PixelsPerXLogicalInch
$sPixelsPerYLogicalInch = $oItem.PixelsPerYLogicalInch
$sScreenWidth = $oItem.ScreenWidth
$sScreenHeight = $oItem.ScreenHeight
$sStatus = $oItem.Status
$sDisplayType = $oItem.DisplayType
$sDeviceID = $oItem.DeviceID
$sAvailability = $oItem.Availability
$sPNPDeviceID = $oItem.PNPDeviceID

;Display Type
Switch $oItem.DisplayType
Case 0
$sDisplayType = "Unknown"
Case 1
$sDisplayType = "Other"
Case 2
$sDisplayType = "MultiScan Color"
Case 3
$sDisplayType = "MultiScan Monochrome"
Case 4
$sDisplayType = "Fixed Frequency Color"
Case 5
$sDisplayType = "Fixed Frequency Monochrome"
Case Else
$sDisplayType = "Unknown"
EndSwitch

;Availability
Switch $oItem.Availability
Case 0
$sAvailability = "Not Found - Error"
Case 1
$sAvailability = "Other"
Case 2
$sAvailability = "Unknown"
Case 3
$sAvailability = "Running or Full Power"
Case 4
$sAvailability = "Warning"
Case 5
$sAvailability = "In Test"
Case 6
$sAvailability = "Not Applicable"
Case 7
$sAvailability = "Power Off"
Case 8
$sAvailability = "Off Line"
Case 9
$sAvailability = "Off Duty"
Case 10
$sAvailability = "Degraded"
Case 11
$sAvailability = "Not Installed"
Case 12
$sAvailability = "Install Error"
Case 13
$sAvailability = "Power Save - Unknown"
Case 14
$sAvailability = "Power Save - Low Power Mode"
Case 15
$sAvailability = "Power Save - Standby"
Case 16
$sAvailability = "Power Cycle"
Case 17
$sAvailability = "Power Save - Warning"
Case Else
$sAvailability = "Not Found"
EndSwitch


Send ("Win32_DesktopMonitor Items" & @CR & "DeviceID = " & $sDeviceID & @CR & _
"Name = " & $sName & @CR & "MonitorType = " & $sMonitorType & @CR & _
"MonitorManufacturer = " & $sMonitorManufacturer & @CR & "PixelsPerXLogicalInch = " & $sPixelsPerXLogicalInch & @CR & _
"PixelsPerYLogicalInch = " & $sPixelsPerYLogicalInch & @CR & "ScreenWidth = " & $sScreenWidth & @CR & _
"ScreenHeight = " & $sScreenHeight & @CR & "DisplayType = " & $sDisplayType & @CR & "Status = " & $sStatus & @CR & _
"Availability = " & $sAvailability & @CR & "PNPDeviceID = " & $sPNPDeviceID & @CR & @CR)
Next

EndIf

EndIf

I've been pulling code from all over the forums and I think I may have got some of this from

Anyone?

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...