norry Posted February 10, 2012 Posted February 10, 2012 (edited) I recently posted this in reply to a Help thread but wanted to share it here so I could hopefully get some feedback on how I could write my code better? I haven't seen this approach when trying to query attached monitors and it has the added advantage that when a monitor is removed or replaced the information is updated. In other approaches the information was read from the registry and that isn't refreshed straight away. Example returned info Monitors Connected: Manufacturer: LPL ProductCode: DE00 Serial: 0 Built: 0/2007 VW202 Manufacturer: ACI ProductCode: 20A2 Serial: 71LB066000 Built: 14/2007 DELL P2310H Manufacturer: DEL ProductCode: D028 Serial: N920R02A0CNL Built: 6/2010 Note the first monitor returned that does not have a friendlyname; this is because it's the laptop screen. expandcollapse popupConsoleWrite(_MonitorInfo()) Func _MonitorInfo() Local $WMIWmiMonitorID Local $sManufacturerName, $sSerialNumberID, $YearOfManufacture, $WeekOfManufacture, $sUserFriendlyName Local $i Local $sMonitorInfo Local $strcomputer = "." Local $objWMIServiceWMI = ObjGet("winmgmts:" & "{impersonationLevel=impersonate}!" & $strcomputer & "rootWMI") ;WmiMonitorID not supported on xp etc. If @OSVersion <> "WIN_XP" And @OSVersion <> "WIN_XPe" And @OSVersion <> "WIN_2000" And @OSVersion <> "WIN_2003" Then If IsObj($objWMIServiceWMI) = 1 Then $WMIWmiMonitorID = $objWMIServiceWMI.ExecQuery("SELECT * FROM WmiMonitorID WHERE Active='True'") $sMonitorInfo = @CRLF & "Monitors Connected: " & @CRLF For $objComputer In $WMIWmiMonitorID $WeekOfManufacture = $objComputer.WeekOfManufacture $YearOfManufacture = $objComputer.YearOfManufacture For $i = 0 To UBound($objComputer.UserFriendlyName) - 1 $sUserFriendlyName = $objComputer.UserFriendlyName($i) If StringLen($sUserFriendlyName) <> 0 Then $sMonitorInfo = $sMonitorInfo & String(Chr($sUserFriendlyName)) EndIf Next $sMonitorInfo = $sMonitorInfo & " Manufacturer: " For $i = 0 To UBound($objComputer.ManufacturerName) - 1 $sManufacturerName = $objComputer.ManufacturerName($i) If StringLen($sManufacturerName) <> 0 Then ;Returns a character corresponding to an ASCII code. $sMonitorInfo = $sMonitorInfo & String(Chr($sManufacturerName)) EndIf Next $sMonitorInfo = $sMonitorInfo & " ProductCode: " For $i = 0 To UBound($objComputer.ProductCodeID) - 1 $sProductCodeID = $objComputer.ProductCodeID($i) If StringLen($sProductCodeID) <> 0 Then $sMonitorInfo = $sMonitorInfo & String(Chr($sProductCodeID)) EndIf Next $sMonitorInfo = $sMonitorInfo & " Serial: " For $i = 0 To UBound($objComputer.SerialNumberID) - 1 $sSerialNumberID = $objComputer.SerialNumberID($i) If StringLen($sSerialNumberID) <> 0 Then $sMonitorInfo = $sMonitorInfo & String(Chr($sSerialNumberID)) EndIf Next $sMonitorInfo = $sMonitorInfo & " Built: " & $WeekOfManufacture & "/" & $YearOfManufacture & @CRLF Next Else $sMonitorInfo = "Error: Not an Object" & @CRLF EndIf EndIf Return $sMonitorInfo EndFunc ;==>_MonitorInfo Edited February 10, 2012 by norry
BrunoJ Posted May 30, 2013 Posted May 30, 2013 (edited) This script works on WIN_7 with one minor tweak. Add backslashes in the appropriate places of line 9. It should read like this: Local $objWMIServiceWMI = ObjGet("winmgmts:" & "{impersonationLevel=impersonate}!\\" & $strcomputer & "\root\WMI")Also, $sProductCodeID was not defined as a local variable. Obviously this is only a problem if the AutoIt option MustDeclareVars is set though. Edited August 21, 2015 by BrunoJ
Geir1983 Posted May 31, 2013 Posted May 31, 2013 Can this return the current resolution of the connected monitors?
water Posted May 31, 2013 Posted May 31, 2013 Run ScriptoMatic (can be found in the Example Scripts forum) and select class "Win32_VideoController" for the horizontal and vertical resolution. My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki
Geir1983 Posted May 31, 2013 Posted May 31, 2013 nice tool, there was alot of information to be read out with this However, the Win32_VideoController only returned resolutions for one monitor.
water Posted May 31, 2013 Posted May 31, 2013 WMIMonitorId only returns very few information. No resolutionn information. All other Monitor classes seem to not provide the information as well. My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now