Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>@steve0, to retrieve the mac address of an <strong>Network Adapter</strong> you can use the <code>WMI</code> and the <a href="http://msdn.microsoft.com/en-us/library/aa394217%28VS.85%29.aspx" rel="nofollow noreferrer"><code>Win32_NetworkAdapterConfiguration</code></a> Class and check the <code>MACAddress</code> property.</p> <p>Check this code:</p> <pre><code>program WMI_MAC; {$APPTYPE CONSOLE} uses SysUtils ,ActiveX ,ComObj ,Variants; function VarToStrNil(Value:Variant):string; //Dummy function to onvert an variant value to string begin if VarIsNull(Value) then Result:='' else Result:=VarToStr(Value); end; Procedure GetMacAddress; var objWMIService : OLEVariant; colItems : OLEVariant; colItem : OLEVariant; oEnum : IEnumvariant; iValue : LongWord; wmiHost, root, wmiClass: string; function GetWMIObject(const objectName: String): IDispatch; var chEaten: Integer; BindCtx: IBindCtx;//for access to a bind context Moniker: IMoniker;//Enables you to use a moniker object begin OleCheck(CreateBindCtx(0, bindCtx)); OleCheck(MkParseDisplayName(BindCtx, StringToOleStr(objectName), chEaten, Moniker));//Converts a string into a moniker that identifies the object named by the string OleCheck(Moniker.BindToObject(BindCtx, nil, IDispatch, Result));//Binds to the specified object end; begin wmiHost := '.'; root := 'root\CIMV2'; wmiClass := 'Win32_NetworkAdapterConfiguration'; objWMIService := GetWMIObject(Format('winmgmts:\\%s\%s',[wmiHost,root])); colItems := objWMIService.ExecQuery(Format('SELECT * FROM %s',[wmiClass]),'WQL',0); oEnum := IUnknown(colItems._NewEnum) as IEnumVariant; while oEnum.Next(1, colItem, iValue) = 0 do //if VarToStrNil(colItem.MACAddress)&lt;&gt;'' then //uncomment if you only want list the interfaces with mac adress //if colItem.IPEnabled then // uncomment if you only want list the active interfaces begin WriteLn('Card Description '+VarToStrNil(colItem.Caption)); WriteLn('MACAddress '+VarToStrNil(colItem.MACAddress)); end; end; begin try CoInitialize(nil); try GetMacAddress; Readln; finally CoUninitialize; end; except on E:Exception do Begin Writeln(E.Classname, ': ', E.Message); Readln; End; end; end. </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload