How to get MAC Address RPC Metod

Hello


I need help with delphi 5
I cant ‘t get it right


I try the NETBIOS funktion and it works
I try the ..
function UuidCreate(Uuid: PGUID): Longint; stdcall;
  external 'rpcrt4.dll' name 'UuidCreate';
    function GetMACAddress: string;
var
   Uuid: TGUID;
begin
     FillChar(Uuid, SizeOf(Uuid), 0);
     if UuidCreate(@Uuid) = 0 then
        GetMACForm.edit1.Text := Format('%2.2x-%2.2x-%2.2x-%2.2x-%2.2x-%2.2x',
                        [Uuid.D4[2], Uuid.D4[3], Uuid.D4[4],
                         Uuid.D4[5], Uuid.D4[6], Uuid.D4[7]])
                 else
        Result := '';
    // end;
…………..

But the rpcrt4.dll is not the same on all machine
If it has Intenetexplorer 5 it don’t work.
It install a version on dll that’s not work    

But now i need it to work without the NETBIOS and Microsoft Network Client or rpcrt4.dll
I use only Novel Client 32
*************************
/ janne

Jan@park.se
LVL 6
Dark_KingAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

intheCommented:
hi,
try use the CoCreateGuid way:


function CoCreateGuid(P:Pointer):Integer;stdcall;external 'ole32.dll';

function GetNicAddr:AnsiString;
var
  T:AnsiString;
  I:Integer;
begin
  Result:='';
  SetLength(T,16);
  if CoCreateGUID(@T[1])=S_OK then begin
    for I:=11 to 15 do Result:=Result+IntToStr(Ord(T[I]))+'.';
    Result:=Result+IntToStr(Ord(T[16]));
  end;
end;
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Dark_KingAuthor Commented:
I wondering

The OLE32.DLL on my second machine is version 4.71.2900.
And it don’t  work on that machine.
On my machine it is version 4.71.3328
0
Dark_KingAuthor Commented:
I look at Internet Explorer 5 setup files
and found Dcom95.exe

It has version on OLE32.DLL 4.71.2900.
0
Introducing Cloud Class® training courses

Tech changes fast. You can learn faster. That’s why we’re bringing professional training courses to Experts Exchange. With a subscription, you can access all the Cloud Class® courses to expand your education, prep for certifications, and get top-notch instructions.

intheCommented:
the versions on mine are 4.71.2900 and it works on them both.

i tried like:

{$R *.DFM}
function CoCreateGuid(P:Pointer):Integer;stdcall;external 'ole32.dll';

Procedure TForm1.Button1Click(Sender: TObject);
function GetNicAddr:AnsiString;
var
  T:AnsiString;
  I:Integer;
begin
  Result:='';
  SetLength(T,16);
  if CoCreateGUID(@T[1])=S_OK then begin
    for I:=11 to 15 do Result:=Result+IntToStr(Ord(T[I]))+'.';
    Result:=Result+IntToStr(Ord(T[16]));
  end
  end;
  Begin
showmessage(getnicaddr);
End;


without using netbios layer i know no other way to get mac address.
0
Dark_KingAuthor Commented:
I need the result in HEX
so I change the IntToStr To IntToHex..

for I:=11 to 15 do Result:=Result+IntToHex(Ord(T[I]),2)+'-';

   getmacform.edit1.Text:=Result+IntToHex(Ord(T[16]),2);

Have I write it wrong

But on my second machine the NIC address is wrong "
(Result:  is not empty)  

I wonder watt’s in the other value in
I:(2 to 10)
0
Dark_KingAuthor Commented:
You say  without using netbios layer i know no other way to get mac adress

Then I wonder watt call WINIPCFG.EXE do to receive mac adress
It function on every machine on my lan  
0
intheCommented:
yes we have debate this issuse here before and know one could find an answer about how winipcfg does it.
:-(

one thing tha was noted in the previous questions was that win95 pcs have it stored in the registry as win95 didnt install netbios by default.
you can get it like below for tthese pc's:

uses REGISTRY;

procedure TForm1.Button1Click(Sender: TObject);
var
  Reg: TRegistry;
  MACaddress: array[1..6] of byte;
  MACsize: integer;
  i: integer;
  status: integer;
  MACaddressString: string;
begin
  Reg := TRegistry.Create;
  try
    Reg.RootKey := HKEY_LOCAL_MACHINE;
    MACsize := 6;
    if Reg.OpenKey('\Software\Description\Microsoft\RPC\uUIDTemporaryData', false) then
      status := Reg.ReadBinaryData('NetworkAddress', MACaddress, MACsize);
  finally
    Reg.CloseKey;
    Reg.Free;
  end;
  {code by David Scott Copus, scottcopus@yahoo.com  :> }
  if status <> 0 then
    begin
      MACaddressString := '';
      for i := 1 to 5 do
        MACaddressString := MACaddressString + format('%2.2x',[MACaddress[i]]) + '-';
      MACaddressString := MACaddressString + format('%2.2x',[MACaddress[6]]);

      memo1.lines.add(Ethernet MAC Address from registry: ' + MACaddressString);
    end
  else
    memo1.lines.add('Registry key not found.');
end;


anoter thing noted:
Both the "GUID" and the "NetBios" ways do read out the right MAC-Adress,but we think only
if the protocol you are using has "ENABLE NETBIOS FOR xxxx (e.g.: TCP/IP)" flag set.
Otherwise it will return a false adress.

(Network->Properties->TCP/IP->Properties->NetBIOS->
"I want to enable NetBIOS over TCP/IP"

Now, since Winipcfg.exe does work properly even
without this flag set, there might be a way to
enable this flag in code, read out the MAC and
disable the flag again.

however noone ever found an answer after several days searching internet , msdn etc:-(
0
laustjensenCommented:
There is a better way!

The MAC of a LAN-machine can be found using the function GetMacAddresses(const Machine: string; const Addresses: TStrings): Integer; found in the JEDI Code Library (JCL). This can be fetched from http://www.delphi-jedi.org. It is free, it works and it doesn't spawn external processes to resolve the MAC.

What it exactly does, I don't know, but it works :o)

Hope any of you can use it. Enjoy :)
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Delphi

From novice to tech pro — start learning today.