1. mike S
  2. PowerBuilder
  3. Wednesday, 28 December 2022 19:15 PM UTC

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) 

GetAdaptersAddresses 

 

John Fauss Accepted Answer Pending Moderation
  1. Monday, 23 January 2023 01:01 AM UTC
  2. PowerBuilder
  3. # 1

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

 

Attachments (1)
Comment
  1. Sivaprakash BKR
  2. Tuesday, 24 January 2023 02:28 AM UTC
Thanks John Fauss. Could be posted in CodeXchange too.

  1. Helpful
  1. John Fauss
  2. Tuesday, 24 January 2023 03:11 AM UTC
I plan to attach/add this sample app to the earlier WMI PB application in CodeXchange and update the text with a description. I appreciate the suggestion.
  1. Helpful
  1. John Fauss
  2. Saturday, 28 January 2023 23:22 PM UTC
I've updated the WMI Class Properties Inspector application in CodeXchange to include the sample application posted in this thread. Here is a link to the CodeXchange post:

https://community.appeon.com/index.php/codeexchange/powerbuilder/281-wmi-windows-management-instrumentation-class-properties-inspector

  1. Helpful
There are no comments made yet.
John Fauss Accepted Answer Pending Moderation
  1. Saturday, 7 January 2023 05:08 AM UTC
  2. PowerBuilder
  3. # 2

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

Attachments (1)
Comment
There are no comments made yet.
Miguel Leeuwe Accepted Answer Pending Moderation
  1. Wednesday, 28 December 2022 22:47 PM UTC
  2. PowerBuilder
  3. # 3

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.

Comment
  1. John Fauss
  2. Thursday, 29 December 2022 03:18 AM UTC
@Mike - I agree with Miguel. I've looked at the Windows API IP_ADAPTER_ADDRESSES structure, and it's a monster - Unions, nested structures, structures whose size varies depending on the Windows version, pointers to structures... what a mess. It's the most complicated WinAPI structure I've ever come across. I'm sure it is possible to accomplish this, but it would likely require much more effort than I'm willing to spend on it. What is the goal you are trying to accomplish?

Have you looked at Windows Management Instrumentation (WMI) to see if there is anything there that satisfies your requirements? In particular, instances of the various classes within the "Networking Device" class category? There's a sample PB app in CodeXchange to obtain/report on WMI information.
  1. Helpful
  1. mike S
  2. Thursday, 29 December 2022 16:48 PM UTC
GetAdaptersInfo has all of those issues too in terms of being a nasty bit of work to figure out the win api. I looked it up since i thought it was a little weird that it gave slightly different information and did not include IP6 addresses. the online docs had the link to the newer version. currently GetAdaptersInfo is fine as IPv4 is still used by everyone and windows still includes it, but i figured i would try to use an api that is future proofed.

--

I use the internal ip address of the user (along with their external ip) to see if they are logged in more than one time on the same machine in order to provide them an option to kill off a possible powerserver orphan.
  1. Helpful 2
There are no comments made yet.
  • Page :
  • 1


There are no replies made for this question yet.
However, you are not allowed to reply to this question.