G
Guest
Hello,
I am porting a legacy program I created in Macromedia Director over to
VB.net and have been learning quite a lot over the last week and half of
porting the application.
One of the things that the Director application did was retrieve a bunch of
system level information (total hard drives, ram, mac address, etc..) I've
found that tapping into WMI through VB.net really helps locate a lot of this
information. One problem I've noticed is that sometimes the code I've pieced
together fails with the following error when trying to derive information
from WMI:
Object reference not set to an instance of an object
My gut feeling is telling me that this information is not available from
within WMI, even though it has an entry on the MSDN website as something
that can be retrieved from within the WMI framework.
The following code fails with the 'Object reference not set to an instance
of an object' on my Windows 2000 machine with the latest patches, .NET
framework, etc...
=============================================================
Imports System.Management
Public Class Form1
Inherits System.Windows.Forms.Form
Public Sub getDNSDomain()
Dim mc As New ManagementClass("Win32_NetworkAdapterConfiguration")
Dim moc As ManagementObjectCollection = mc.GetInstances()
Dim mo As ManagementObject
For Each mo In moc
If mo("Caption").ToString() <> "" Then
TextBox1.Text = mo("DNSDomain").ToString()
End If
Next
End Sub
mo.Dispose()
mo = Nothing
moc.Dispose()
moc = Nothing
mc.Dispose()
mc = Nothing
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
getDNSDomain()
End Sub
End Class
============================================================================
====
I run the application in Debug mode and the error dialog appears at this
line:
TextBox1.Text = mo("DNSDomain").ToString()
I have a feeling that the mo object has not been populated with information
and thus the error is displayed.
Is there a way within VB.net to tell if an object is actually an object? In
Director I would use ObjectP to test to see if the object is actually an
object.
I guess what I would like to do is make sure that I can trap for errors
whenever I request a piece of information from WMI and it's not available on
the system instead of having the error dialog box appear each time.
Also, is there a more non-neophyte way to march through WMI information
instead of writing 100 functions to grab all the information I am trying to
retrieve?
Any suggestions would be greatly appreciated.
Cheers,
devin
I am porting a legacy program I created in Macromedia Director over to
VB.net and have been learning quite a lot over the last week and half of
porting the application.
One of the things that the Director application did was retrieve a bunch of
system level information (total hard drives, ram, mac address, etc..) I've
found that tapping into WMI through VB.net really helps locate a lot of this
information. One problem I've noticed is that sometimes the code I've pieced
together fails with the following error when trying to derive information
from WMI:
Object reference not set to an instance of an object
My gut feeling is telling me that this information is not available from
within WMI, even though it has an entry on the MSDN website as something
that can be retrieved from within the WMI framework.
The following code fails with the 'Object reference not set to an instance
of an object' on my Windows 2000 machine with the latest patches, .NET
framework, etc...
=============================================================
Imports System.Management
Public Class Form1
Inherits System.Windows.Forms.Form
Public Sub getDNSDomain()
Dim mc As New ManagementClass("Win32_NetworkAdapterConfiguration")
Dim moc As ManagementObjectCollection = mc.GetInstances()
Dim mo As ManagementObject
For Each mo In moc
If mo("Caption").ToString() <> "" Then
TextBox1.Text = mo("DNSDomain").ToString()
End If
Next
End Sub
mo.Dispose()
mo = Nothing
moc.Dispose()
moc = Nothing
mc.Dispose()
mc = Nothing
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
getDNSDomain()
End Sub
End Class
============================================================================
====
I run the application in Debug mode and the error dialog appears at this
line:
TextBox1.Text = mo("DNSDomain").ToString()
I have a feeling that the mo object has not been populated with information
and thus the error is displayed.
Is there a way within VB.net to tell if an object is actually an object? In
Director I would use ObjectP to test to see if the object is actually an
object.
I guess what I would like to do is make sure that I can trap for errors
whenever I request a piece of information from WMI and it's not available on
the system instead of having the error dialog box appear each time.
Also, is there a more non-neophyte way to march through WMI information
instead of writing 100 functions to grab all the information I am trying to
retrieve?
Any suggestions would be greatly appreciated.
Cheers,
devin