2014-10-06 26 views
2

我在 HKEY_LOCAL_MACHINE \ SYSTEM看着監視器列表\ CURRENTCONTROLSET \枚舉\ DISPLAY確定是否屏幕處於活動狀態或不從Windows 8註冊表

在Windows 7中,有每個屏幕節點下的一個子項命名爲「控制「表示屏幕是否處於活動狀態。 在Windows 8中沒有這樣的子項。

如何從Windows 8註冊表中確定顯示器是否處於活動狀態?

回答

0

試試這個代碼(我驗證了這一點):

Public Function GetMonitorDetails() As List(Of WSGetLoginData.Monitor) 
    'Open the Display Reg-Key 
    Dim wmiPNPID As New List(Of String) 

    Dim mc As System.Management.ManagementClass 
    Dim moc As ManagementObjectCollection 
    Dim PathPNPID As String 


    mc = New ManagementClass("Win32_DesktopMonitor") 
    moc = mc.GetInstances() 
    For Each mo In moc 
     PathPNPID = mo.Item("PNPDeviceID") 
     If PathPNPID.Trim <> "" AndAlso PathPNPID.Contains("\") Then 
      PathPNPID = PathPNPID.Substring(PathPNPID.LastIndexOf("\") + 1) 
      wmiPNPID.Add(PathPNPID.ToUpper) 
     End If 
    Next 

    Dim Display As RegistryKey = Registry.LocalMachine 
    Dim bFailed As [Boolean] = False 
    Dim obj_ListMonitor As New List(Of WSGetLoginData.Monitor) 
    Try 
     Display = Registry.LocalMachine.OpenSubKey("SYSTEM\CurrentControlSet\Enum\DISPLAY") 
    Catch 
     bFailed = True 
    End Try 

    If Not bFailed And (Display IsNot Nothing) Then 

     'Get all MonitorIDss 
     For Each sMonitorID As String In Display.GetSubKeyNames() 
      Dim MonitorID As RegistryKey = Display.OpenSubKey(sMonitorID) 

      If MonitorID IsNot Nothing Then 
       'Get all Plug&Play ID's 
       For Each sPNPID As String In MonitorID.GetSubKeyNames() 
        Dim PnPID As RegistryKey = MonitorID.OpenSubKey(sPNPID) 
        If PnPID IsNot Nothing Then 
         Dim sSubkeys As String() = PnPID.GetSubKeyNames() 

         'Check if Monitor is active 
         'If Array.IndexOf(sSubkeys, "Control") > -1 Then 
         If Not wmiPNPID Is Nothing AndAlso wmiPNPID.Count > 0 AndAlso wmiPNPID.Contains(sPNPID.ToUpper) Then 
          If Array.IndexOf(sSubkeys, "Device Parameters") > -1 Then 
           Dim DevParam As RegistryKey = PnPID.OpenSubKey("Device Parameters") 
           Dim sSerial As String = "" 
           Dim sModel As String = "" 

           'Define Search Keys 
           Dim sSerFind As New String(New Char() {ChrW(0), ChrW(0), ChrW(0), ChrW(&HFF)}) 
           Dim sModFind As New String(New Char() {ChrW(0), ChrW(0), ChrW(0), ChrW(&HFC)}) 

           'Get the EDID code 
           Dim bObj As Byte() = TryCast(DevParam.GetValue("EDID", Nothing), Byte()) 
           If bObj IsNot Nothing Then 
            'Get the 4 Vesa descriptor blocks 
            Dim sDescriptor As String() = New String(3) {} 
            sDescriptor(0) = Encoding.[Default].GetString(bObj, &H36, 18) 
            sDescriptor(1) = Encoding.[Default].GetString(bObj, &H48, 18) 
            sDescriptor(2) = Encoding.[Default].GetString(bObj, &H5A, 18) 
            sDescriptor(3) = Encoding.[Default].GetString(bObj, &H6C, 18) 


            'Search the Keys 
            For Each sDesc As String In sDescriptor 
             If sDesc.Contains(sSerFind) Then 
              sSerial = sDesc.Substring(4).Replace(vbNullChar, "").Trim() 
             End If 
             If sDesc.Contains(sModFind) Then 
              sModel = sDesc.Substring(4).Replace(vbNullChar, "").Trim() 
             End If 


            Next 
           End If 

           If Not String.IsNullOrEmpty(sSerial) AndAlso sSerial.Trim <> "" Then 
            Dim insertar As Boolean = True 
            If Not obj_ListMonitor Is Nothing AndAlso obj_ListMonitor.Count > 0 Then 
             For k As Integer = 0 To obj_ListMonitor.Count - 1 
              If obj_ListMonitor(k).SerialNumber.Trim = sSerial Then 
               insertar = False 
               Exit For 
              End If 
             Next 
            End If 
            If insertar Then 
             Dim obj_monitor As New WSGetLoginData.Monitor 

             obj_monitor.UUID = Security.FingerPrint.Value(sModel & sSerial) 
             obj_monitor.Modelo = sModel 
             obj_monitor.SerialNumber = sSerial 
             obj_ListMonitor.Add(obj_monitor) 
            End If 
           End If 
          End If 
         End If 
        End If 
       Next 
      End If 
     Next 
    End If 
    Return obj_ListMonitor 
End Function 
+0

但WMI不包含有關我們連接外接顯示器的信息。 – jain 2016-09-01 06:09:10

相關問題