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
Beispiel Form1 mit Aufruf von Drive :
Spoiler anzeigen
Projekt - Verweis hinzufügen- System.Management
Classe erstellen unter:
Projekt - Klasse hinzufügen
Und Code rein !
Code für Classe:
VB.NET-Quellcode
- Option Strict On
- Imports System.Management
- Public Class WMI
- Public Class Hardware
- Public Shared Function GetProperties(ByVal [Class] As Win32) As Collections.Generic.Dictionary(Of String, String())
- Dim MOS As ManagementObjectSearcher = New ManagementObjectSearcher("Select * from Win32" & [Class].ToString)
- Dim MOC As ManagementObjectCollection = MOS.Get
- Dim MO As ManagementObject
- Dim PD As PropertyData
- Dim HWList As New Collections.Generic.Dictionary(Of String, String())
- For Each MO In MOC
- For Each PD In MO.Properties
- If Not PD.Value Is Nothing Then
- If HWList.ContainsKey(PD.Name) = False Then
- HWList.Add(PD.Name, GetProperty([Class], PD.Name))
- End If
- End If
- Next
- Next
- Return HWList
- End Function
- Public Shared Function GetProperty(ByVal [Class] As Win32, ByVal [Property] As String) As String()
- Dim MOS As ManagementObjectSearcher = New ManagementObjectSearcher("Select " & [Property] & " from Win32" & [Class].ToString)
- Dim MOC As ManagementObjectCollection = MOS.Get
- Dim MO As New ManagementObject
- Dim Values As New List(Of String)
- Try
- For Each MO In MOC
- Values.Add(CStr(MO.GetPropertyValue([Property])))
- Next
- Catch ex As Exception
- Return Nothing
- End Try
- Return Values.ToArray
- End Function
- Public Enum Win32 As Integer
- 'Cooling Device Classes
- _Fan
- _HeatPipe
- _Refrigeration
- _TemperatureProbe
- 'Input Device Classes
- _Keyboard
- _PointingDevice
- 'Mass Storage Classes
- _AutochkSetting
- _CDROMDrive
- _DiskDrive
- _FloppyDrive
- _PhysicalMedia
- _TapeDrive
- 'Motherboard, Controller, and Port Classes
- _1394Controller
- _1394ControllerDevice
- _AllocatedResource
- _AssociatedProcessorMemory
- _BaseBoard
- _BIOS
- _Bus
- _CacheMemory
- _ControllerHasHub
- _DeviceBus
- _DeviceMemoryAddress
- _DeviceSettings
- _DMAChannel
- _FloppyController
- _IDEController
- _IDEControllerDevice
- _InfraredDevice
- _IRQResource
- _MemoryArray
- _MemoryArrayLocation
- _MemoryDevice
- _MemoryDeviceArray
- _MemoryDeviceLocation
- _MotherboardDevice
- _OnBoardDevice
- _ParallelPort
- _PCMCIAController
- _PhysicalMemory
- _PhysicalMemoryArray
- _PhysicalMemoryLocation
- _PNPAllocatedResource
- _PNPDevice
- _PNPEntity
- _PortConnector
- _PortResource
- _Processor
- _SCSIController
- _SCSIControllerDevice
- _SerialPort
- _SerialPortConfiguration
- _SerialPortSetting
- _SMBIOSMemory
- _SoundDevice
- _SystemBIOS
- _SystemDriverPNPEntity
- _SystemEnclosure
- _SystemMemoryResource
- _SystemSlot
- _USBController
- _USBControllerDevice
- _USBHub
- 'Networking Device Classes
- _NetworkAdapter
- _NetworkAdapterConfiguration
- _NetworkAdapterSetting
- 'Power Classes
- _AssociatedBattery
- _Battery
- _CurrentProbe
- _PortableBattery
- _PowerManagementEvent
- _UninterruptiblePowerSupply
- _VoltageProbe
- 'Printing Classes
- _DriverForDevice
- _Printer
- _PrinterConfiguration
- _PrinterController
- _PrinterDriver
- _PrinterDriverDll
- _PrinterSetting
- _PrintJob
- _TCPIPPrinterPort
- 'Telephony Classes
- _POTSModem
- _POTSModemToSerialPort
- 'Video and Monitor Classes
- _DesktopMonitor
- _DisplayConfiguration
- _DisplayControllerConfiguration
- _VideoConfiguration
- _VideoController
- _VideoSettings
- End Enum
- End Class
- End Class
Beispiel Form1 mit Aufruf von Drive :
VB.NET-Quellcode
- Option Strict On
- Public Class Form1
- Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
- Dim DiskDrive = WMI.Hardware.GetProperties(WMI.Hardware.Win32._DiskDrive)
- Dim Disk_Infos As String = ""
- For Each infos As String In DiskDrive!Caption
- Disk_Infos &= infos & vbNewLine
- Next
- MsgBox(Disk_Infos)
- End Sub
- End Class