The declarations in D7 are wrong: char <> byte.
function GetAdapterInfo(Lana: Char): string; var Adapter: TAdapterStatus; NCB: TNCB; begin FillChar(NCB, SizeOf(NCB), 0); NCB.ncb_command := byte(NCBRESET); NCB.ncb_lana_num := byte(Lana); if Netbios(@NCB) <> byte(NRC_GOODRET) then begin Result := 'Address not known'; Exit; end; FillChar(NCB, SizeOf(NCB), 0); NCB.ncb_command := byte(NCBASTAT); NCB.ncb_lana_num := byte(Lana); NCB.ncb_callname[0] := byte('*'); FillChar(Adapter, SizeOf(Adapter), 0); NCB.ncb_buffer := @Adapter; NCB.ncb_length := SizeOf(Adapter); if Netbios(@NCB) <> byte(NRC_GOODRET) then begin Result := 'Address not known'; Exit; end; Result := IntToHex(byte(Adapter.adapter_address[0]), 2) + '-' + IntToHex(byte(Adapter.adapter_address[1]), 2) + '-' + IntToHex(byte(Adapter.adapter_address[2]), 2) + '-' + IntToHex(byte(Adapter.adapter_address[3]), 2) + '-' + IntToHex(byte(Adapter.adapter_address[4]), 2) + '-' + IntToHex(Byte(Adapter.adapter_address[5]), 2); end; function GetMACAddress: string; var AdapterList: TLanaEnum; NCB: TNCB; begin FillChar(NCB, SizeOf(NCB), 0); NCB.ncb_command := byte(NCBENUM); NCB.ncb_buffer := @AdapterList; NCB.ncb_length := SizeOf(AdapterList); Netbios(@NCB); if Byte(AdapterList.length) > 0 then Result := GetAdapterInfo(char(AdapterList.lana[0])) else Result := 'Address not known'; end;
Just leave the casting to byte away. Only required at one location. the rest matches the structures.Nothing changed.
oh, and:
function GetAdapterInfo(Lana: UCHAR): string;
Nothing changed.it works for me tm, so then the question becomes: what is the target and do you have enough rights ? antivirus ?
I already went through all the options, the outcome is one.
Does not work.
[Netbios is not supported on Windows Vista, Windows Server 2008, and subsequent versions of the operating system]
Nothing changed.it works for me tm, so then the question becomes: what is the target and do you have enough rights ? antivirus ?
I already went through all the options, the outcome is one.
Does not work.
edit: and for good measures:
edit2:and a slightly modified version that is able to show info for all adapters it was able to find
program test; {$MODE OBJFPC} uses windows, nb30, sysutils, strutils; function GetAdapterInfo(Lana: UCHAR): string; var Adapter: TAdapterStatus; NCB: TNCB; begin NCB := default(TNCB); // FillChar(NCB, SizeOf(NCB), 0); NCB.ncb_command := NCBRESET; NCB.ncb_lana_num := Lana; if Netbios(@NCB) <> NRC_GOODRET then begin Result := 'Address not known'; Exit; end; NCB := default(TNCB); // FillChar(NCB, SizeOf(NCB), 0); NCB.ncb_command := NCBASTAT; NCB.ncb_lana_num := Lana; NCB.ncb_callname[0] := Byte('*'); // NCB.ncb_callname := Asc('*'); Adapter := default(TAdapterStatus); // FillChar(Adapter, SizeOf(Adapter), 0); NCB.ncb_buffer := @Adapter; NCB.ncb_length := SizeOf(Adapter); if Netbios(@NCB) <> NRC_GOODRET then begin Result := 'Address not known'; Exit; end; Result := IntToHex(Byte(Adapter.adapter_address[0]), 2) + '-' + IntToHex(Byte(Adapter.adapter_address[1]), 2) + '-' + IntToHex(Byte(Adapter.adapter_address[2]), 2) + '-' + IntToHex(Byte(Adapter.adapter_address[3]), 2) + '-' + IntToHex(Byte(Adapter.adapter_address[4]), 2) + '-' + IntToHex(Byte(Adapter.adapter_address[5]), 2); end; function GetMACAddress: string; var AdapterList: TLanaEnum; NCB: TNCB; AdapterIndex: UCHAR; Info: string; begin NCB := default(TNCB); // FillChar(NCB, SizeOf(NCB), 0); NCB.ncb_command := NCBENUM; NCB.ncb_buffer := @AdapterList; NCB.ncb_length := SizeOf(AdapterList); if Netbios(@NCB) = NRC_GOODRET then begin if AdapterList.length > 0 then // if Byte(AdapterList.length) > 0 begin Result := ''; for AdapterIndex := 0 to AdapterList.length-1 do begin WriteStr ( Info, 'Adapter[', AdapterIndex, '].MacAddress = ', GetAdapterInfo(AdapterList.lana[AdapterIndex]), IfThen(AdapterIndex < AdapterList.length-1, ', ', '') ); Result := Result + Info; end; end else Result := 'No adapters found'; end else Result := 'Unable to obtain adapterlist'; end; var S: String; begin S := GetMacAddress; WriteLn('MacAddressess are : ', S); end.
What i do bad?(What exact part of:
...did you not understood ?Quote[Netbios is not supported on Windows Vista, Windows Server 2008, and subsequent versions of the operating system]
ty man, i go sleep...What i do bad?(What exact part of:...did you not understood ?Quote[Netbios is not supported on Windows Vista, Windows Server 2008, and subsequent versions of the operating system]
Or, to put it into other words: you are using the wrong Operating System for that code to work.
@gcrazydv:code from rvk good work.
just use the code that was linked to by rvk and you won't have nightmare's :D