I assume that you want to get the MAC address in order to implement some kind of DRM, inventory or classification system, since you tried to get a permanent MAC address instead of the current one.
You seem to have forgotten that there is even an administratively superimposed MAC address (in other words: a "forced" MAC address).
Some drivers allow you to do this on the Device Properties page of the Advanced tab (for example, my Marvell network adapter allows me to do this), while others do not allow you to do this (read: they do not support this property).
However, all this ends with a registry value: HKLM\SYSTEM\CurrentControlSet\Control\Class\{4D36E972-E325-11CE-BFC1-08002BE10318}\xxxx\NetworkAddress with type REG_SZ . Here you can set a different MAC address, different from the original one, in the form of "01020304abcd" (6 bytes, normal hexadecimal without : delimiters or 0x prefix). After you install it, restart the computer, and when you turn it on, the new MAC address will work.
I have a motherboard with two integrated Marvell network cards and a NETGEAR USB WiFi network interface. Marvell one supports changing the MAC address: if you set the NetworkAddress value in the registry, you will also see the new value on the driver properties page, and it will take effect immediately, without having to restart (if you change it from the device's Property page). The following are the results of reading the MAC address using various methods:
GetAdaptersInfo : New MAC AddressIOCTL_NDIS_QUERY_GLOBAL_STATS : original MAC addressMSNdis_EthernetPermanentAddress : Source MAC Address
I tried to add the NetworkAddress value to the registry for the NETGEAR USB WiFi network adapter, and the result was the following:
GetAdaptersInfo : New MAC AddressIOCTL_NDIS_QUERY_GLOBAL_STATS : new MAC addressMSNdis_EthernetPermanentAddress : New MAC Address
The original MAC addresses have disappeared.
Thus, in order not to be deceived by the "malicious" user, you always need to check the registry value HKLM\SYSTEM\CurrentControlSet\Control\Class\{4D36E972-E325-11CE-BFC1-08002BE10318}\xxxx\NetworkAddress . If this is installed, I think it’s better not to trust this network adapter at all, since it is the driver implementation that decides what will be presented to you using various methods.
Some information to get this registry key:
Microsoft Documentation on HKLM \ SYSTEM \ CurrentControlSet \ Class
According to Microsoft documentation on this page,
There is a subkey for each class that is named using the installation class GUID
Therefore, we select the subsection {4D36E972-E325-11CE-BFC1-08002BE10318} (aka GUID_DEVCLASS_NET , defined in <devguid.h> and more <devguid.h> described here )
Again, according to Microsoft documentation,
Each subsection of a class contains other subsections, known as software keys (or driver keys) for each device instance of this class installed on the system. Each of these software keys is assigned a name using the device instance identifier, which is a four-digit ordinal value with a base of-10. The xxxx part is a 4-character text representation of a positive integer, starting at 0
Thus, you can navigate through the subsections from 0000, 0001, 0002 to the number of network adapters in your system.
The documentation stops here: I did not find any other documentation about various registry values or something like that.
However, in each of these subsections, you can find REG_SZ values that can help you link GetAdaptersInfo() , MSNdis_EthernetPermanentAddress , Win32_NetworkAdapter and Device Instance ID worlds (and this answers your question).
Registry Values:
DeviceInstanceID : its value, which is not surprising, is the device instance IDNetCfgInstanceId : its value is the AdapterName member of the IP_ADAPTER_INFO structure returned by GetAdaptersInfo() . He is also a member of the Win32_NetworkAdapter WMI class GUID .- Remember
NetworkAddress : if there is a valid MAC address, the driver can report it as the MAC address used by GetAdaptersInfo() , MSNdis_EthernetPermanentAddress and IOCTL_NDIS_QUERY_GLOBAL_STATS !
Then, as you said, the only connection between MSNdis_EthernetPermanentAddress WMI MSNdis_EthernetPermanentAddress and the rest of the "world" is made by its member InstanceName . You can associate it with the Description member of the IP_ADAPTER_INFO structure returned by GetAdaptersInfo() . Although it may be a localized name, it seems unique to the system (for my two integrated Marvell network adapters, "# 2" is added to the second name).
Final note:
Having said all of the above, the user can disable WMI ...