Roland (topwizprogramming.com) has sample code for the older version (for windows versions prior to XP) which is: GetAdaptersInfo
that older version does not have all the information available that GetAdaptersAddresses has (ipV6 in particular)
Roland (topwizprogramming.com) has sample code for the older version (for windows versions prior to XP) which is: GetAdaptersInfo
that older version does not have all the information available that GetAdaptersAddresses has (ipV6 in particular)
Attached is a simpler, more complete sample app that identifies all active/enabled network adapters and obtains property names and values for each, including the IPv4 and/or IPv6 addresses. There can be more than one active network adapter due to virtual private networks, which use virtual network adapters. This sample app uses OLE to interface with Windows Management Instrumentation (WMI) to obtain information about network adapters from the Win32_NetworkAdapter and Win32_NetworkAdapterConfiguration classes. Performance is acceptable, as much as I can tell in my limited testing.
After considerable effort, I've been unable to get the GetAdaptersAddresses Windows API function working from PB. It works well from a C/C++ console application, but calling this particular external function from PB always results in an R0015 runtime error and I'm unable to determine why.
The querying of WMI classes and the parsing of the information returned by a query is made pretty easy using the non-visual objects and structures included in the sample app. WMI may seem intimidating at first glance, but the objects included here make it easy to obtain hardware-related information in a PB application.
Below is a link to some online documentation regarding the Win32_xxxxx computer system hardware classes, in case anyone wants to experiment with other WMI classes.
https://learn.microsoft.com/en-us/windows/win32/cimwin32prov/computer-system-hardware-classes
Mike -
I've been looking at the GetAdaptersAddresses WinAPI function over the past several evenings. I'm pretty sure it can be called from PB and I'm hoping to be able to do just that in the near future, but it's going to take a little time. There are 15 different WinAPI structures that have to be mimicked in PB just to be able to create the PB version of the IP_ADAPTER_ADDRESSES structure. I'm able to call it from a C++ console app and extract IPv6 addresses, so I know what has to be done, it's just a matter of persuading PB to do it.
In researching this issue, I looked at the Win32_NetworkAdapter and Win32_NetworkAdapterConfiguration classes in WMI (Windows Management Instrumentation) and found IP addresses there.
So... I borrowed code from a CodeXchange sample program I wrote a while back on obtaining information from WMI, and this evening put together a little PB app that (1) identifies which network adapter in Windows is the active one, and (2) obtains the adapter name, MAC address, IPv4 address and IPv6 address of that active network adapter. I'm attaching the app for your perusal. If you can use it to satisfy your needs, great. If not, I'll re-post if and when I get the WinAPI function working in the (hopefully) not too distant future.
Caveat emptor: I've only run this app on my home PC, so I make no guarantees that it will work in all situations. Please let me know how it works out for you.
Best regards, John
Hi Mike,
Never used it, but I'd say write a C++ dll or do something like this in C# ? https://bytes.com/topic/c-sharp/answers/254385-getadaptersaddresses-c
Most likely you could also use powerscript powershell to do the select statement used in that link.
regards.
https://community.appeon.com/index.php/codeexchange/powerbuilder/281-wmi-windows-management-instrumentation-class-properties-inspector