inno-setup – 在Inno Setup中获取MAC地址

我尝试了下面的代码来获取Inno安装程序中的mac地址,但收到错误

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

我已经在应用程序文件夹中复制了ISID.dll仍然出现上述错误.

如果我遗失了某些东西,请告诉我….

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;

最佳答案 这是一个在Windows上使用WMI获取所有MAC地址的脚本.

[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;
点赞