本文整理汇总了VB.NET中System.Management.ManagementClass.GetInstances方法的典型用法代码示例。如果您正苦于以下问题:VB.NET ManagementClass.GetInstances方法的具体用法?VB.NET ManagementClass.GetInstances怎么用?VB.NET ManagementClass.GetInstances使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。
在下文中一共展示了ManagementClass.GetInstances方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的VB.NET代码示例。
示例1: Sample
' 导入命名空间
Imports System.Management
Class Sample
Public Overloads Shared Function _
Main(ByVal args() As String) As Integer
Dim c As New ManagementClass("Win32_Process")
Dim o As ManagementObject
For Each o In c.GetInstances()
Console.WriteLine( _
"Next instance of Win32_Process : {0}", o("Name"))
Next o
End Function
End Class
示例2: Sample
' 导入命名空间
Imports System.Management
Class Sample
Public Overloads Shared Function _
Main(ByVal args() As String) As Integer
Dim opt As New EnumerationOptions
' Will enumerate instances of the given class and any subclasses.
opt.EnumerateDeep = True
Dim mngmtClass As New ManagementClass("CIM_Service")
Dim o As ManagementObject
For Each o In mngmtClass.GetInstances(opt)
Console.WriteLine(o("Name"))
Next o
End Function
End Class
示例3: AsyncGetExample
' 导入命名空间
Imports System.Management
Public Class AsyncGetExample
Public Sub New()
Dim c As New ManagementClass("Win32_Process")
Dim ob As New ManagementOperationObserver
AddHandler ob.ObjectReady, AddressOf Me.NewObject
AddHandler ob.Completed, AddressOf Me.Done
c.GetInstances(ob)
While Not Me.Completed
System.Threading.Thread.Sleep(1000)
End While
'Here you can use the object
End Sub
Private finished As Boolean = False
Private Sub NewObject(ByVal sender As Object, _
ByVal e As ObjectReadyEventArgs)
Console.WriteLine("New result arrived: {0}", _
e.NewObject("Name"))
End Sub
Private Sub Done(ByVal sender As Object, _
ByVal e As CompletedEventArgs)
Console.WriteLine("async Get completed !")
finished = True
End Sub
Private ReadOnly Property Completed() As Boolean
Get
Return finished
End Get
End Property
Public Shared Function Main(ByVal args() _
As String) As Integer
Dim asyncGet As New AsyncGetExample
Return 0
End Function
End Class