"Christian Reizlein" wrote:
I have been reading some docs at
http://msdn.microsoft.com/en-us/library/aa394595.aspx and i cant get it to
work in Vb.net
does anyone know how to call a method of a particular object in VB.net?
all i can do is "query" a result set and then display it properties in a
while or for each, but i dont understand exactly how to get only one object
and call a method.
Dim myObjectSearcher As New
System.Management.ManagementObjectSearcher("SELECT * From
Win32_NetworkAdapter WHERE PhysicalAdapter=1")
For Each obj As System.Management.ManagementObject In
myObjectSearcher.Get()
MsgBox(obj.GetPropertyValue("MACAddress"))
Next
Any help please? :)
Use ManagementObject.InvokeMethod():
http://msdn.microsoft.com/en-us/library/f9ck6sf2.aspx http://msdn.microsoft.com/en-us/library/ssk42c11.aspx
The samples show how to execute Win32_Process.Create() static method, but
you can also use it with WMI class instances:
Dim s As New ManagementObjectSearcher( _
"SELECT * FROM Win32_Service")
For Each service As ManagementObject In s.Get()
Dim retVal As Object = _
service.InvokeMethod("InterrogateService", Nothing)
Console.WriteLine(retVal)
Next
If you want to invoke a method on a single instance, you can use WMI object
path to reference it:
Dim service As New ManagementObject( _
"Win32_Service.Name='ClipSrv'")
Dim StartMode() As Object = New Object() {"Manual"}
Dim retVal As Object = _
service.InvokeMethod("ChangeStartMode", StartMode)
Console.WriteLine(retVal)
--
urkec