- Код: Выделить всё
'Beispiel: VB .Net - WMI - Win32_PhysicalMedia - Laufwerksinformationen ermitteln - Seriennummer ermitteln
'
Option Explicit On
Option Strict On
Imports System.Management
Imports System.Text
Imports System.Environment
Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) _
Handles MyBase.Load
With Me
.CenterToScreen()
End With
End Sub
Private Function InfoMessage() As String
Dim sb As StringBuilder = New StringBuilder
With sb
.Append("\nThe Serial number property is a manufacturer-allocated number")
.Append("\nused to identify the physicalmedia.")
.Replace("\n", NewLine)
End With
Return sb.ToString()
End Function
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) _
Handles Button1.Click
Dim Result As String = SerialNumber()
Me.TextBox1.Text = ""
If Result IsNot Nothing Then Me.TextBox1.Text = Result & NewLine & Me.InfoMessage() Else Me.TextBox1.Text = "Fehler"
End Sub
Private Shared ReadOnly Property SerialNumber() As String
Get
Const query As String = "SerialNumber"
Try
Dim moc As ManagementObjectCollection = InitManagement() 'ManagementObjectCollection - Ругается Тип не определен
If moc IsNot Nothing Then
For Each mo As ManagementObject In moc 'ManagementObject - Ругается Тип не определен
If mo.Properties(query).Value.ToString() IsNot Nothing Then
Return mo.Properties(query).Value.ToString()
Else
Return Nothing
End If
Next
Else
Return Nothing
End If
Catch
End Try
Return Nothing
End Get
End Property
Private Shared Function InitManagement() As ManagementObjectCollection '- Ругается Тип не определен
Try
Dim query As String = "Select * from Win32_PhysicalMedia"
Dim mos As ManagementObjectSearcher = New ManagementObjectSearcher(query) ' ManagementObjectSearcher - Ругается Тип не определен
Dim moc As ManagementObjectCollection = mos.Get() 'ManagementObjectCollection - Ругается Тип не определен
Return moc
Catch
Return Nothing
End Try
Return Nothing
End Function
End Class
Пишу на VB2008. Самые первые шаги. Учусь на примерах. И ни как не могу понять чего ей не хватает.