Link to home
Start Free TrialLog in
Avatar of kidd12
kidd12

asked on

Delphi get in use mac address

hello friends i am picked various commands for pick mac address in delphi and not picked one good, i am need pick the active network mac address, in my pc i am have virtualbox and more than one mac address and when i run program in delphi pick another mac address not pick the mac i am using.
Please help me
Avatar of Thommy
Thommy
Flag of Germany image

Have you already tried this???

Get NIC MAC Address
http://www.prestwood.com/ASPSuite/KB/Document_View.asp?QID=100258
ASKER CERTIFIED SOLUTION
Avatar of Thommy
Thommy
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of rinfo
rinfo

First simplest way to get MAC address is using windows API from Ole32.dll.
This will get you the first MAC address in case of multiple mac addresses(fro multiple cards).


function CoCreateGuid(var guid: TGUID): HResult; stdcall; far external 'ole32.dll';

function Get_MACAddress: string;
var
  g: TGUID;
  i: Byte;
begin
  Result := '';
  CoCreateGUID(g);
  for i := 2 to 7 do
    Result := Result + IntToHex(g.D4[i], 2);
end;

Open in new window

Avatar of ThievingSix
@rinfo:

"The CoCreateGuid function calls the RPC function UuidCreate"
"For security reasons, UuidCreate was modified so that it no longer uses a machine's MAC address to generate UUIDs."

The simplest solution if you already have JCL (http://wiki.delphi-jedi.org/index.php?title=JEDI_Code_Library) installed is to use GetMacAddresses() found in JclSysInfo.pas.

The reason I prefer this method is because it incorporates the other methods shown here as well as a few others just in case on method fails.