How To Get Info Of All Monitors With Python On Windows?
I need a way to get the manufacturer name and the data string of all the connected monitors in Windows and with Python. My final goal is a function that returns this for example: [
Solution 1:
This can be done by executing PowerShell command from your python script. To discover multi-monitor configuration information on your computer you use powershell Get-WmiObject win32_desktopmonitor command. Command output looks like this:
__GENUS :2__CLASS :Win32_DesktopMonitor__SUPERCLASS :CIM_DesktopMonitor__DYNASTY :CIM_ManagedSystemElement__RELPATH :Win32_DesktopMonitor.DeviceID="DesktopMonitor1"__PROPERTY_COUNT :28__DERIVATION : {CIM_DesktopMonitor, CIM_Display, CIM_UserDevice,
CIM_LogicalDevice...}
__SERVER :SQUALL__NAMESPACE :root\cimv2__PATH :\\SQUALL\root\cimv2:Win32_DesktopMonitor.DeviceID="DesktopMonitor1"Availability :3Bandwidth :Caption :LGIPS237(Analog)ConfigManagerErrorCode :0ConfigManagerUserConfig :FalseCreationClassName :Win32_DesktopMonitorDescription :LGIPS237(Analog)DeviceID :DesktopMonitor1DisplayType :ErrorCleared :ErrorDescription :InstallDate :IsLocked :LastErrorCode :MonitorManufacturer :LGMonitorType :LGIPS237(Analog)Name :LGIPS237(Analog)PixelsPerXLogicalInch :96PixelsPerYLogicalInch :96PNPDeviceID :DISPLAY\GSM587D\5&2494DFB6&0&UID1048848PowerManagementCapabilities :PowerManagementSupported :ScreenHeight :1080ScreenWidth :1920Status :OKStatusInfo :SystemCreationClassName :Win32_ComputerSystemSystemName :SQUALL
We need to get section Name, so use regex. The final code is:
import subprocess
import re
proc = subprocess.Popen(['powershell', 'Get-WmiObject win32_desktopmonitor;'], stdout=subprocess.PIPE)
res = proc.communicate()
monitors = re.findall('(?s)\r\nName\s+:\s(.*?)\r\n', res[0].decode("utf-8"))
print(monitors)
The result is:
['LG IPS237(Analog)']
Post a Comment for "How To Get Info Of All Monitors With Python On Windows?"