EnumDisplayDevices返回值是Generic PnP Monitor – c#

当我想要返回它们的实际名称时,我连接了几个监视器 – 例如:LEN L192p,IBM 190p。

我看过这个问题:

如何获取实际的Monitor名称? 如解决方案对话框中所示

但是当我运行它时,我的识别错误。 它检测到我的笔记本电脑,但是我正在使用的其他两个屏幕(LEN L192p,IBM 190p)未被检测到,而是编写了Generic PnP Monitor

谁知道会出现什么问题?

这是输出: 在此处输入图像描述

和代码:

  using System; using System.Collections.Generic; using System.Linq; using System.Runtime.InteropServices; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; namespace Screens { class Program { [DllImport("user32.dll")] public static extern bool EnumDisplayDevices(string lpDevice, uint iDevNum, ref DISPLAY_DEVICE lpDisplayDevice, uint dwFlags); [Flags()] public enum DisplayDeviceStateFlags : int { /// The device is part of the desktop. AttachedToDesktop = 0x1, MultiDriver = 0x2, /// The device is part of the desktop. PrimaryDevice = 0x4, /// Represents a pseudo device used to mirror application drawing for remoting or other purposes. MirroringDriver = 0x8, /// The device is VGA compatible. VGACompatible = 0x16, /// The device is removable; it cannot be the primary display. Removable = 0x20, /// The device has more display modes than its output devices support. ModesPruned = 0x8000000, Remote = 0x4000000, Disconnect = 0x2000000 } [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)] public struct DISPLAY_DEVICE { [MarshalAs(UnmanagedType.U4)] public int cb; [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 32)] public string DeviceName; [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 128)] public string DeviceString; [MarshalAs(UnmanagedType.U4)] public DisplayDeviceStateFlags StateFlags; [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 128)] public string DeviceID; [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 128)] public string DeviceKey; } static void Main(string[] args) { var device = new DISPLAY_DEVICE(); device.cb = Marshal.SizeOf(device); try { for (uint id = 0; EnumDisplayDevices(null, id, ref device, 0); id++) { device.cb = Marshal.SizeOf(device); EnumDisplayDevices(device.DeviceName, 0, ref device, 0); device.cb = Marshal.SizeOf(device); Console.WriteLine("id={0}, name={1}, devicestring={2}", id, device.DeviceName, device.DeviceString); if (device.DeviceName == null || device.DeviceName == "") continue; } string x = Console.ReadLine(); } catch (Exception ex) { Console.WriteLine(String.Format("{0}", ex.ToString())); } } 

发生这种情况是因为屏幕没有安装驱动程序,因此实际设备本身正在使用Generic PnP Monitor Driver运行。 查看设备管理器,您将看到。

我很确定如果不安装显示器的制造商驱动程序,就无法实现您想要实现的目标。