Pc Informationen auslesen mit (( WMI ))

    • VB.NET
    • .NET (FX) 4.0

    Es gibt 6 Antworten in diesem Thema. Der letzte Beitrag () ist von 00yoshi.

      Pc Informationen auslesen mit (( WMI ))

      Verweis hinzufügen unter:
      Projekt - Verweis hinzufügen- System.Management

      Classe erstellen unter:
      Projekt - Klasse hinzufügen

      Und Code rein !

      Code für Classe:

      Spoiler anzeigen

      VB.NET-Quellcode

      1. ​Option Strict On
      2. Imports System.Management
      3. Public Class WMI
      4. Public Class Hardware
      5. Public Shared Function GetProperties(ByVal [Class] As Win32) As Collections.Generic.Dictionary(Of String, String())
      6. Dim MOS As ManagementObjectSearcher = New ManagementObjectSearcher("Select * from Win32" & [Class].ToString)
      7. Dim MOC As ManagementObjectCollection = MOS.Get
      8. Dim MO As ManagementObject
      9. Dim PD As PropertyData
      10. Dim HWList As New Collections.Generic.Dictionary(Of String, String())
      11. For Each MO In MOC
      12. For Each PD In MO.Properties
      13. If Not PD.Value Is Nothing Then
      14. If HWList.ContainsKey(PD.Name) = False Then
      15. HWList.Add(PD.Name, GetProperty([Class], PD.Name))
      16. End If
      17. End If
      18. Next
      19. Next
      20. Return HWList
      21. End Function
      22. Public Shared Function GetProperty(ByVal [Class] As Win32, ByVal [Property] As String) As String()
      23. Dim MOS As ManagementObjectSearcher = New ManagementObjectSearcher("Select " & [Property] & " from Win32" & [Class].ToString)
      24. Dim MOC As ManagementObjectCollection = MOS.Get
      25. Dim MO As New ManagementObject
      26. Dim Values As New List(Of String)
      27. Try
      28. For Each MO In MOC
      29. Values.Add(CStr(MO.GetPropertyValue([Property])))
      30. Next
      31. Catch ex As Exception
      32. Return Nothing
      33. End Try
      34. Return Values.ToArray
      35. End Function
      36. Public Enum Win32 As Integer
      37. 'Cooling Device Classes
      38. _Fan
      39. _HeatPipe
      40. _Refrigeration
      41. _TemperatureProbe
      42. 'Input Device Classes
      43. _Keyboard
      44. _PointingDevice
      45. 'Mass Storage Classes
      46. _AutochkSetting
      47. _CDROMDrive
      48. _DiskDrive
      49. _FloppyDrive
      50. _PhysicalMedia
      51. _TapeDrive
      52. 'Motherboard, Controller, and Port Classes
      53. _1394Controller
      54. _1394ControllerDevice
      55. _AllocatedResource
      56. _AssociatedProcessorMemory
      57. _BaseBoard
      58. _BIOS
      59. _Bus
      60. _CacheMemory
      61. _ControllerHasHub
      62. _DeviceBus
      63. _DeviceMemoryAddress
      64. _DeviceSettings
      65. _DMAChannel
      66. _FloppyController
      67. _IDEController
      68. _IDEControllerDevice
      69. _InfraredDevice
      70. _IRQResource
      71. _MemoryArray
      72. _MemoryArrayLocation
      73. _MemoryDevice
      74. _MemoryDeviceArray
      75. _MemoryDeviceLocation
      76. _MotherboardDevice
      77. _OnBoardDevice
      78. _ParallelPort
      79. _PCMCIAController
      80. _PhysicalMemory
      81. _PhysicalMemoryArray
      82. _PhysicalMemoryLocation
      83. _PNPAllocatedResource
      84. _PNPDevice
      85. _PNPEntity
      86. _PortConnector
      87. _PortResource
      88. _Processor
      89. _SCSIController
      90. _SCSIControllerDevice
      91. _SerialPort
      92. _SerialPortConfiguration
      93. _SerialPortSetting
      94. _SMBIOSMemory
      95. _SoundDevice
      96. _SystemBIOS
      97. _SystemDriverPNPEntity
      98. _SystemEnclosure
      99. _SystemMemoryResource
      100. _SystemSlot
      101. _USBController
      102. _USBControllerDevice
      103. _USBHub
      104. 'Networking Device Classes
      105. _NetworkAdapter
      106. _NetworkAdapterConfiguration
      107. _NetworkAdapterSetting
      108. 'Power Classes
      109. _AssociatedBattery
      110. _Battery
      111. _CurrentProbe
      112. _PortableBattery
      113. _PowerManagementEvent
      114. _UninterruptiblePowerSupply
      115. _VoltageProbe
      116. 'Printing Classes
      117. _DriverForDevice
      118. _Printer
      119. _PrinterConfiguration
      120. _PrinterController
      121. _PrinterDriver
      122. _PrinterDriverDll
      123. _PrinterSetting
      124. _PrintJob
      125. _TCPIPPrinterPort
      126. 'Telephony Classes
      127. _POTSModem
      128. _POTSModemToSerialPort
      129. 'Video and Monitor Classes
      130. _DesktopMonitor
      131. _DisplayConfiguration
      132. _DisplayControllerConfiguration
      133. _VideoConfiguration
      134. _VideoController
      135. _VideoSettings
      136. End Enum
      137. End Class
      138. End Class


      Beispiel Form1 mit Aufruf von Drive :
      Spoiler anzeigen

      VB.NET-Quellcode

      1. Option Strict On
      2. Public Class Form1
      3. Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
      4. Dim DiskDrive = WMI.Hardware.GetProperties(WMI.Hardware.Win32._DiskDrive)
      5. Dim Disk_Infos As String = ""
      6. For Each infos As String In DiskDrive!Caption
      7. Disk_Infos &= infos & vbNewLine
      8. Next
      9. MsgBox(Disk_Infos)
      10. End Sub
      11. End Class​

      Counterbug schrieb:

      Wird bei enum.ToString() tatsächlich der Name ausgegeben?
      Hättest Du das probiert, wärst Du schneller an dieser Information gewesen. Selbst die MSDN ist hier hilfreich:
      Bilder
      • Enum.png

        10,92 kB, 1.367×73, 285 mal angesehen
      Falls Du diesen Code kopierst, achte auf die C&P-Bremse.
      Jede einzelne Zeile Deines Programms, die Du nicht explizit getestet hast, ist falsch :!:
      Ein guter .NET-Snippetkonverter (der ist verfügbar).
      Programmierfragen über PN / Konversation werden ignoriert!
      ich wollte mal was mit Temperatur probieren, da kam nur ein error:

      VB.NET-Quellcode

      1. Dim DiskDrive = WMI.Hardware.GetProperties(WMI.Hardware.Win32._HeatPipe)
      2. Dim Disk_Infos As String = ""
      3. For Each infos As String In DiskDrive!Caption
      4. Disk_Infos &= infos & vbNewLine
      5. Next
      6. MsgBox(Disk_Infos)

      Das war eine KeyNotFoundException bei DiskDrive!Caption