Solved

VB.net 'ManagementObjectCollection' is not defined.

Posted on 2014-02-28
3
557 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:murbro
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:murbro
ID: 39896892
Thank you both
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
How to sort a list of objects using an item in an enclosed list 5 50
VB.NET 2008 Publish Error 2 33
Generate Numbers in JQuery file 11 66
SSRS 2016 Rendering HTML tables 3 26
If you're writing a .NET application to connect to an Access .mdb database and use pre-existing queries that require parameters, you've come to the right place! Let's say the pre-existing query(qryCust) in Access takes a Date as a parameter and l…
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

839 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