Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

VB.net 'ManagementObjectCollection' is not defined.

Posted on 2014-02-28
3
Medium Priority
?
640 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
3 Comments
 
LVL 75

Assisted Solution

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

Accepted Solution

by:
Jacques Bourgeois (James Burger) earned 1000 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

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

Question has a verified solution.

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

Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
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.
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …
Suggested Courses

963 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