Imports System.Management
Public Class Form1
'Oggetto WMI
Private mos As ManagementObjectSearcher = Nothing
Enum CIM_Setting As Integer
BitsPerPel = 0
Caption = 1
Description = 2
DeviceName = 3
DisplayFlags = 4
DisplayFrequency = 5
DitherType = 6
DriverVersion = 7
ICMIntent = 8
ICMMethod = 9
LogPixels = 10
PelsHeight = 11
PelsWidth = 12
SettingID = 13
SpecificationVersion = 14
End Enum
Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
'Recupero tutte le informazioni della classe Win32_DisplayConfiguration e le inserisco nell'oggeto ManagementObjectSearcher
mos = InitDisplayConfiguration()
'La valoreDisplay conterra il valore desiderato
Dim valoreDisplay As String = Nothing
valoreDisplay = Me.InterrogazioneWin32Display(CIM_Setting.Caption)
'valoreDisplay = Me.InterrogazioneWin32Display(CIM_Setting.SpecificationVersion)
'valoreDisplay = Me.InterrogazioneWin32Display(CIM_Setting.DeviceName)
'valoreDisplay = Me.InterrogazioneWin32Display(CIM_Setting.DisplayFrequency)
'valoreDisplay = Me.InterrogazioneWin32Display(CIM_Setting.SettingID
'basta scrivere CIM_Setting. appare un elenco di valori da inserire
MsgBox("Risultato valore = " & valoreDisplay)
End Sub
Private Function InitDisplayConfiguration() As ManagementObjectSearcher
Try
Dim query As String = "Select * from Win32_DisplayConfiguration"
Dim sq As SelectQuery = New SelectQuery(query)
Dim mos As ManagementObjectSearcher = New ManagementObjectSearcher(sq)
If mos IsNot Nothing Then
Return mos
Else : Return Nothing
End If
Catch ex As Exception
MessageBox.Show(ex.Message.ToString(), "Exception")
End Try
Return Nothing
End Function
Private ReadOnly Property InterrogazioneWin32Display(ByVal Parametro As CIM_Setting) As String
Get
Try
Dim Stringa As String = Nothing
Select Case Parametro
Case CIM_Setting.BitsPerPel
Stringa = "BitsPerPel"
Exit Select
Case CIM_Setting.Caption
Stringa = "Caption"
Exit Select
Case CIM_Setting.Description
Stringa = "Description"
Exit Select
Case CIM_Setting.DeviceName
Stringa = "DeviceName"
Exit Select
Case CIM_Setting.DisplayFlags
Stringa = "DisplayFlags"
Exit Select
Case CIM_Setting.DisplayFrequency
Stringa = "DisplayFrequency"
Exit Select
Case CIM_Setting.DitherType
Stringa = "DitherType"
Exit Select
Case CIM_Setting.DriverVersion
Stringa = "DriverVersion"
Exit Select
Case CIM_Setting.ICMIntent
Stringa = "ICMIntent"
Exit Select
Case CIM_Setting.ICMMethod
Stringa = "ICMMethod"
Exit Select
Case CIM_Setting.LogPixels
Stringa = "LogPixels"
Exit Select
Case CIM_Setting.PelsHeight
Stringa = "PelsHeight"
Exit Select
Case CIM_Setting.PelsWidth
Stringa = "PelsWidth"
Exit Select
Case CIM_Setting.SettingID
Stringa = "SettingID"
Exit Select
Case CIM_Setting.SpecificationVersion
Stringa = "SpecificationVersion"
Exit Select
Case Else
Stringa = "DeviceName"
Exit Select
End Select
Dim Result As String = ""
If Me.mos IsNot Nothing Then
For Each mbo As ManagementBaseObject In Me.mos.Get()
Result = mbo(Stringa).ToString()
Next
Return Result
Else
Return ""
End If
Catch
Return ""
End Try
End Get
End Property
End Class