Ashish
Ashish

Reputation: 41

Get MAC address in Inno Setup

I tried the below code to get the mac address in Inno Setup but getting an error as

Internal error: ExtractTemporaryFile: The file "ISID.dll" was not found.

I have copied the ISID.dll in the application folder still getting the above error.

Please let me know if I am missing something....:

function GetMacAddress(output:string): Integer;
external 'GetMACAddress@files:ISID.dll stdcall';

function GetMacAdd(Output: string): string;
var
  ClassName: String;
  Ret: Integer;
begin
  SetLength(ClassName, 256); 
  Ret := GetMacAddress(PChar(ClassName)); 
  Result := Copy(ClassName, 1, Ret);
end;

Upvotes: 4

Views: 1703

Answers (1)

bgcode
bgcode

Reputation: 335

Here is a script which uses WMI on Windows to get all MAC addresses.

[Code]
type
  TMacAddressEntry = record
    MacAddress: string;
  end;

  TMacAddressesList = array of TMacAddressEntry;

function GetMacAddressesList(out List: TMacAddressesList): Integer;
var
  I: Integer;
  WQLQuery: string;
  WbemLocator: Variant;
  WbemServices: Variant;
  WbemObject: Variant;
  WbemObjectSet: Variant;
begin
  Result := 0;

  WbemLocator := CreateOleObject('WbemScripting.SWbemLocator');
  WbemServices := WbemLocator.ConnectServer('localhost', 'root\cimv2');

  WQLQuery := 'Select * from Win32_NetworkAdapterConfiguration where IPEnabled=true';

  WbemObjectSet := WbemServices.ExecQuery(WQLQuery);
  if not VarIsNull(WbemObjectSet) and (WbemObjectSet.Count > 0) then
  begin
    Result := WbemObjectSet.Count;
    SetArrayLength(List, WbemObjectSet.Count);
    for I := 0 to WbemObjectSet.Count - 1 do
    begin
      WbemObject := WbemObjectSet.ItemIndex(I);
      if not VarIsNull(WbemObject) then
      begin
        List[I].MacAddress := WbemObject.MACAddress;
      end;
    end;
  end;
end;

Upvotes: 2

Related Questions