1. Deva Shanmuga
  2. PowerBuilder
  3. Saturday, 22 June 2024 09:23 AM UTC

Hello Experts,

I am using the following code to get IP address, System MAC Address and System Name of the local machine where PB application is running, It is running successfull when the internet is connected, If there is no Internet I am getting time error.


OLEObject objWMIService, IPConfigSet, IPConfig

objWMIService = CREATE OLEObject;
rs = objWMIService.ConnectToObject("winmgmts:{impersonationLevel=impersonate}!//./root/cimv2");

IPConfigSet = objWMIService.ExecQuery("Select * from Win32_NetworkAdapterConfiguration Where IPEnabled=TRUE")

IPConfig = IPConfigSet.ItemIndex(0)
s_mac = (IPConfig.Properties_.Item("MACAddress").Value);
s_description = (IPConfig.Properties_.Item("Description").Value);
s_IP = (IPConfig.Properties_.Item("IPAddress").Value(0));


Is there any other method to retrieve the IP Address, System MAC address and System name?



Deva S

Roland Smith Accepted Answer Pending Moderation
  1. Saturday, 22 June 2024 21:47 PM UTC
  2. PowerBuilder
  3. # 1

My Winsock example gives a list of IP addresses the computer has and the public IP address.



There are no comments made yet.
John Fauss Accepted Answer Pending Moderation
  1. Saturday, 22 June 2024 17:37 PM UTC
  2. PowerBuilder
  3. # 2

Hi, Deva -


I have tested using the WMI Class Properties Inspector application that I published in CodeXchange in 2021:


and when there is no available internet connection, the IPEnabled property of the Win32_NetworkAdapterConfiguration class for all class instances is FALSE, so your query is likely failing because it specifies "Where IPEnabled=TRUE".

I'm no expert, but I suggest you consider a two-step approach.

First, obtain the InterfaceIndex, MACAddress and NetEnabled properties for all instances of the Win32_NetworkAdapter class (yes, I know this WMI class is deprecated) where PhysicalAdapter=TRUE.

Next, for each instance found but only if NetEnabled=TRUE, obtain the IPAddress property of the Win32_NetworkAdapterConfiguration class where InterfaceIndex=x (x=the InterfaceIndex value from each instance returned in the first query). Of course, if there is no active internet connection, there will be no instances from the first query where NetEnabled=TRUE.

Finally, one way to obtain the name of the computer system is to use WMI to query the Caption property of the Win32_ComputerSystem class. Another is to use the GetComputerNameW Windows API function.



Best regards, John

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.