473,238 Members | 1,794 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,238 software developers and data experts.

Getting MAC Address from a Network Card

Hello, I'm trying to find a way to retrieve the MAC address from a network
card in a Visual C++ .NET managed application.

I've found some examples in C#, but I just can't get them to work in C++.
Here's what I've found in C#:

using System.Management;
.....
ManagementClass mc = new
ManagementClass("Win32_NetworkAdapterConfiguration ");
ManagementObjectCollection moc = mc.GetInstances();
foreach(ManagementObject mo in moc)
{
if((bool)mo["IPEnabled"] == true)
Console.WriteLine("MAC address\t{0}", mo["MacAddress"].ToString());
mo.Dispose();
}

Now, I'm trying to convert this to make it usable in C++, but the second
line has me thrown for a loop. Here's the beginning of what I've got :

#using <system.management.dll>
using namespace System::Management;

int _tmain(void)
{
ManagementClass* mc = new
ManagementClass("Win32_NetworkAdapterConfiguration ");
return 0;
}

But even this won't compile....giving me the error
"System::ComponentModel::Component", the compiler cannot find this type; it
is defined in the assembly 'System'

Can anyone help me out with this? Please? I'm losing hair by the hour.
:-)

/\/\ark
Feb 7 '06 #1
3 6025
Hello Mark,

Now, I'm trying to convert this to make it usable in C++, but the second
line has me thrown for a loop. Here's the beginning of what I've got :

#using <system.management.dll>
using namespace System::Management;

int _tmain(void)
{
ManagementClass* mc = new
ManagementClass("Win32_NetworkAdapterConfiguration ");
return 0;
}

But even this won't compile....giving me the error
"System::ComponentModel::Component", the compiler cannot find this type;
it is defined in the assembly 'System'


Did you create a new console project for this?
I've pasted your code in a new Managed console project, and it compiles
without a problem.
#include "stdafx.h"
#using <mscorlib.dll>
#using <system.management.dll>

using namespace System;
using namespace System::Management;

int _tmain()
{
Console::WriteLine(S"Hello World");
ManagementClass* mc = new
ManagementClass("Win32_NetworkAdapterConfiguration ");
return 0;
}

If you reused an older project or something, then try starting from a new
console project.
If that doesn't work, then maybe you can post a reproduction project?

--

Kind regards,
Bruno.
br**********************@hotmail.com
Remove only "_nos_pam"
Feb 7 '06 #2
The error message clearly states that you are missing an assembly reference,
it also tells you which assembly contains the type, so you need to add this:

#using <system.dll>
Willy.

"Mark Prenter" <an**@anon.com> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
| Hello, I'm trying to find a way to retrieve the MAC address from a network
| card in a Visual C++ .NET managed application.
|
| I've found some examples in C#, but I just can't get them to work in C++.
| Here's what I've found in C#:
|
| using System.Management;
| ....
| ManagementClass mc = new
| ManagementClass("Win32_NetworkAdapterConfiguration ");
| ManagementObjectCollection moc = mc.GetInstances();
| foreach(ManagementObject mo in moc)
| {
| if((bool)mo["IPEnabled"] == true)
| Console.WriteLine("MAC address\t{0}", mo["MacAddress"].ToString());
| mo.Dispose();
| }
|
| Now, I'm trying to convert this to make it usable in C++, but the second
| line has me thrown for a loop. Here's the beginning of what I've got :
|
| #using <system.management.dll>
| using namespace System::Management;
|
| int _tmain(void)
| {
| ManagementClass* mc = new
| ManagementClass("Win32_NetworkAdapterConfiguration ");
| return 0;
| }
|
| But even this won't compile....giving me the error
| "System::ComponentModel::Component", the compiler cannot find this type;
it
| is defined in the assembly 'System'
|
| Can anyone help me out with this? Please? I'm losing hair by the hour.
| :-)
|
| /\/\ark
|
|
Feb 7 '06 #3
Thanks to all for the replies. I've never used ManagementObjects before so
I guess I have quite a bit of learning to do.

For those of you playing along at home.....here's the translated C++ .NET
code for looping through all network adapters and retrieving the MAC
addresses:

#include "stdafx.h"
#include <tchar.h>

#using <mscorlib.dll>
#using <system.management.dll>
#using <system.dll>

using namespace System;
using namespace System::Management;
using namespace System::Collections;

// This is the entry point for this application
int _tmain(void)
{
ManagementClass* mc = new
ManagementClass("Win32_NetworkAdapterConfiguration ");
ManagementObjectCollection* moc = mc->GetInstances();
ManagementObjectCollection::ManagementObjectEnumer ator* mo =
moc->GetEnumerator();
while (mo->MoveNext())
{
ManagementBaseObject* CurrentManagementObject = mo->get_Current();
Object* IPEnabled =
CurrentManagementObject->GetPropertyValue(L"IPEnabled");
if (Convert::ToBoolean(IPEnabled->ToString()) == true)
{
Object* MacAddress =
CurrentManagementObject->GetPropertyValue(L"MacAddress");
Console::WriteLine("MAC address\t{0}", MacAddress->ToString());
}
}
return 0;
}

Thanks again!!!!

/\/\ark
"Willy Denoyette [MVP]" <wi*************@telenet.be> wrote in message
news:O$**************@TK2MSFTNGP12.phx.gbl...
The error message clearly states that you are missing an assembly
reference,
it also tells you which assembly contains the type, so you need to add
this:

#using <system.dll>
Willy.

"Mark Prenter" <an**@anon.com> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
| Hello, I'm trying to find a way to retrieve the MAC address from a
network
| card in a Visual C++ .NET managed application.
|
| I've found some examples in C#, but I just can't get them to work in
C++.
| Here's what I've found in C#:
|
| using System.Management;
| ....
| ManagementClass mc = new
| ManagementClass("Win32_NetworkAdapterConfiguration ");
| ManagementObjectCollection moc = mc.GetInstances();
| foreach(ManagementObject mo in moc)
| {
| if((bool)mo["IPEnabled"] == true)
| Console.WriteLine("MAC address\t{0}", mo["MacAddress"].ToString());
| mo.Dispose();
| }
|
| Now, I'm trying to convert this to make it usable in C++, but the second
| line has me thrown for a loop. Here's the beginning of what I've got :
|
| #using <system.management.dll>
| using namespace System::Management;
|
| int _tmain(void)
| {
| ManagementClass* mc = new
| ManagementClass("Win32_NetworkAdapterConfiguration ");
| return 0;
| }
|
| But even this won't compile....giving me the error
| "System::ComponentModel::Component", the compiler cannot find this type;
it
| is defined in the assembly 'System'
|
| Can anyone help me out with this? Please? I'm losing hair by the hour.
| :-)
|
| /\/\ark
|
|

Feb 7 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
by: Ben Xia | last post by:
Is there some way can detect MAC address with PHP? any help will be appreciate. Ben
4
by: MLH | last post by:
It has been mentioned that a ghosted machine or a machine linked by cable modem and USB may result in my reading a MAC address other than one burned onto a NIC in the machine. That being the case,...
9
by: John J. Hughes II | last post by:
I have a system where my software sits on one server and interacts with another server running MS SQL. My software recieves connects via a socket layer on the internet and does it's thing with the...
15
by: Roberto Hernández | last post by:
I develop a software and I want to protect it whit some unique ID of a computer Can I get the serial ID of the motherboard?
8
by: pigeonrandle | last post by:
Hi, This started off being a question along the lines of "how do i get the local machine ip address?", which can be done using .... String sIPAddress =...
5
by: Paul Bromley | last post by:
How do I know which IP address is active?? I have created the following class and this works well, but the first address it obtains on my machine is not the active one - in fact I do not know...
2
by: Salad | last post by:
If I work on my app on my standalone, things are always fast. If I have an non-split app on the network it runs fast. If I split the app and have both the front end and backend on the network...
6
by: Ryan Liu | last post by:
Hi, If I want to uniquely identify a computer. I can read CPU ID or Mac Address. I heard, but is this true: some BIOS can block CPU ID from being read? (In this case, will I get an exception,...
3
by: tag | last post by:
I'm trying to add an IP address to a pc's network card. In C++ I used the IPHlpApi.lib's function AddIPAddress. Is there a built in way to add an IP Address in C#? Thanks in advance...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.