2

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:

["Lenovo LTN116AT06407", "BenQ G615HDPL"]

I found a software (madVR), that get what I need but I don't know how it does.

madvr display identification

baltazer
  • 259
  • 1
  • 5
  • 12
  • would [this SO QA](http://stackoverflow.com/questions/22724802/how-to-get-the-display-names-of-multiple-monitors-with-the-win32-api) help? – Pynchia Aug 03 '15 at 18:11
  • Had you seen http://stackoverflow.com/a/8251896/4828720 and http://stackoverflow.com/questions/22724802/how-to-get-the-display-names-of-multiple-monitors-with-the-win32-api ? – bugmenot123 Mar 14 '16 at 21:38
  • Look into the win32all library for Python. – SuperA Aug 03 '15 at 18:16

1 Answers1

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                : 3
Bandwidth                   : 
Caption                     : LG IPS237(Analog)
ConfigManagerErrorCode      : 0
ConfigManagerUserConfig     : False
CreationClassName           : Win32_DesktopMonitor
Description                 : LG IPS237(Analog)
DeviceID                    : DesktopMonitor1
DisplayType                 : 
ErrorCleared                : 
ErrorDescription            : 
InstallDate                 : 
IsLocked                    : 
LastErrorCode               : 
MonitorManufacturer         : LG
MonitorType                 : LG IPS237(Analog)
Name                        : LG IPS237(Analog)
PixelsPerXLogicalInch       : 96
PixelsPerYLogicalInch       : 96
PNPDeviceID                 : DISPLAY\GSM587D\5&2494DFB6&0&UID1048848
PowerManagementCapabilities : 
PowerManagementSupported    : 
ScreenHeight                : 1080
ScreenWidth                 : 1920
Status                      : OK
StatusInfo                  : 
SystemCreationClassName     : Win32_ComputerSystem
SystemName                  : 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)']
prusya
  • 674
  • 5
  • 7
  • 1
    Doesn't work. I get only 3 things (Name, DeviceID and MonitorManufacter) with the powershell command and they are too generic: LCD 1366x768 as Name. – baltazer Aug 03 '15 at 22:14
  • What OS version do you use? Does it have proper display driver installed? – prusya Aug 03 '15 at 22:21
  • 1
    This is Windows 8.1, no display driver installed, only the generic one. – baltazer Aug 03 '15 at 22:25
  • 1
    Windows 10 isn't different, the name of my monitor is being shown in the settings, but using `Get-WmiObject win32_desktopmonitor` in the powershell gives me even less information. Not even the resolution. – dieserniko Sep 04 '21 at 15:25