Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get hardware MAC address on Windows

I'm playing around with retrieving the MAC address from the NIC - there are a variety of ways to get it, this article covers the most common:

http://www.codeguru.com/Cpp/I-N/network/networkinformation/article.php/c5451

I'm currently using the GetAdaptersInfo method, which seems the most bulletproof, but if the MAC address has been set via the registry:

http://www.mydigitallife.info/2008/06/30/how-to-change-or-spoof-mac-address-in-windows-xp-vista-server-20032008-mac-os-x-unix-and-linux/

Then it reports the MAC address that it has been changed to. The only way I've found to actually get the true MAC is to remove the registry entry, restart the NIC, get the MAC via GetAdaptersInfo, then replace the registry entry, and restart the NIC. While it gets the job done, it's hardly transparent to the user.

Is there any other methods that anyone is familiar with, that will return the hardware MAC regardless of what the registry is set to? Ideally I'd like a solution that works on XP on up.

Thanks in advance!

like image 292
Mark Avatar asked May 05 '09 06:05

Mark


1 Answers

My guess is that in the linked CodeGuru article, the Miniport solution is likely to overcome the problem you describe, albeit painful to implement. The reason I think this is that I have used the GetAdaptersInfo solution myself in the past, and noticed that the MAC address will change without reboot when an adapter is added, e.g. a Bluetooth adapter providing PAN services.

Perhaps rather than rebooting after changing the registry setting, you could try stopping and restarting the relevent network services. You could easily check this manually prior to looking for a programmatic solution.

(n.b. the above is all guess work. If you try it and it works, perhaps add a post for those trying to do the same in future).

like image 171
SmacL Avatar answered Sep 17 '22 14:09

SmacL