Solved

VB.net 'ManagementObjectCollection' is not defined.

Posted on 2014-02-28
3
595 Views
Last Modified: 2014-03-01
Hi

I get the following errors in the code below. What references/imports do I have to make

  Error      81      Type 'ManagementObjectCollection' is not defined.
Error      82      Type 'ManagementObject' is not defined.
Error      80      Type 'ManagementClass' is not defined.


  Friend Function GetAllMACAddresses() As String

        Dim mc As ManagementClass = New ManagementClass("Win32_NetworkAdapterConfiguration")
        Dim moc As ManagementObjectCollection = mc.GetInstances()
        Dim MACAddress As String = String.Empty
        For Each mo As ManagementObject In moc
            If CBool(mo("IPEnabled")) Then MACAddress &= mo("MacAddress").ToString() & ";"
            mo.Dispose()
        Next
        Return MACAddress.Trim.Trim(";").Trim
    End Function
0
Comment
Question by:Murray Brown
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 75

Assisted Solution

by:käµfm³d 👽
käµfm³d   👽 earned 250 total points
ID: 39895161
0
 
LVL 40

Accepted Solution

by:
Jacques Bourgeois (James Burger) earned 250 total points
ID: 39895698
What kaufmed implies is that you need to first define a reference to the System.Management.dll in through the Project...Add Reference menu, so that Visual Studio recognize that class.

Then, you should add an Imports System.Management command at the top of the file so that the compiler recognizes that namespace.

You must do that whenever you use classes out of the "ordinary" classes that are used more regularly.
0
 

Author Closing Comment

by:Murray Brown
ID: 39896892
Thank you both
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…

630 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question