Here's a couple of things for you to try Wolf. If these don't work for you, we can try something else.
Code: Select all
#INTERNET_CONNECTION_MODEM = $1
#INTERNET_CONNECTION_LAN = $2
#INTERNET_CONNECTION_PROXY = $4
#INTERNET_RAS_INSTALLED = $10
#INTERNET_CONNECTION_OFFLINE = $20
#INTERNET_CONNECTION_CONFIGURED = $40
Procedure.s checkConnection()
Shared conn$
connectionName$ = Space(256)
tf = InternetGetConnectedStateEx_(@lpdwFlags.l, @connectionName$, 256, 0)
If tf
conn$ = "Connection name is: " + connectionName$ + Chr(13) + Chr(10)
If lpdwFlags & #INTERNET_CONNECTION_CONFIGURED
conn$ + "Local system has a valid connection to the Internet, but it might or might not be currently connected."
EndIf
If lpdwFlags & #INTERNET_CONNECTION_OFFLINE
conn$ + "Local system is in offline mode." + Chr(13) + Chr(10)
EndIf
If lpdwFlags & #INTERNET_RAS_INSTALLED
conn$ + "Local system has RAS installed." + Chr(13) + Chr(10)
EndIf
If lpdwFlags & #INTERNET_CONNECTION_PROXY
conn$ + "Local system uses a proxy server to connect to the Internet." + Chr(13) + Chr(10)
EndIf
If lpdwFlags & #INTERNET_CONNECTION_LAN
conn$ + "Local system uses a local area network to connect to the Internet." + Chr(13) + Chr(10)
EndIf
If lpdwFlags & #INTERNET_CONNECTION_MODEM
conn$ + "Local system uses a modem To connect To the Internet." + Chr(13) + Chr(10)
EndIf
Else
conn$ = "No Internet connection detected."
EndIf
ProcedureReturn conn$
EndProcedure
If OpenWindow(0, 10, 10, 400, 150, #PB_Window_SystemMenu | #PB_Window_ScreenCentered, "InternetGetConnectedStateEx")
If CreateGadgetList(WindowID(0))
ButtonGadget(0, 10, 10, 200, 20, "Check connection")
StringGadget(1, 10, 40, 380, 100, "", #PB_String_MultiLine)
EndIf
EndIf
Repeat
Event = WaitWindowEvent()
Select Event
Case #PB_EventGadget
If EventGadgetID() = 0
checkConnection()
SetGadgetText(1, conn$)
EndIf
Case #PB_Event_CloseWindow
Quit = #True
EndSelect
Until Quit = #True
End
Another option is to
look at some code from ABBKlaus here. You can get the actual connection name just as it appears in the Network Connections folder but you'll have to read a registry key first by adding a few lines of code.
Code: Select all
keyRead.l = 0
connectionName$ = Space(255)
datasize.l = 255
myConnections$ = PeekS(@tempipinfo\AdapterName)
myKey$ = "SYSTEM\CurrentControlSet\Control\Network\{4D36E972-E325-11CE-BFC1-08002BE10318}\" + myConnections$ + "\Connection"
RegOpenKeyEx_(#HKEY_LOCAL_MACHINE, myKey$, 0, #KEY_READ, @keyRead)
RegQueryValueEx_(keyRead, "Name", 0, 0, @connectionName$, @datasize)
RegCloseKey_(keyRead)
Debug "Connection Name : "+connectionName$
Here's the complete code with my addition to ABBKlaus's great code. Run code with debugger for Debug output.
Code: Select all
;***************************************************************************
; original code from ABBKlaus with my addition from line 51 to 59 and line 85
; ***************************************************************************
; http://msdn.microsoft.com/library/default.asp?url=/library/en-us/iphlp/iphlp/getadaptersinfo.asp
; with the help of IPHlpAPI.inc from the Powerbasic include-file for the structures
; Microsoft isn´t quite a help here :-)
Structure IP_ADDR_STRING
pNext.l
IpAddress.b[16]
IpMask.b[16]
Context.l
EndStructure
Structure IP_ADAPTER_INFO
Next.l
ComboIndex.l
AdapterName.b[260] ; MAX_ADAPTER_NAME_LENGTH + 4
Description.b[132] ; MAX_ADAPTER_DESCRIPTION_LENGTH + 4
AdressLength.l
Address.b[8] ; MAX_ADAPTER_ADDRESS_LENGTH
Index.l
Type.l
DhcpEnabled.l
CurrentIpAddressPTR.l
IpAddressList.IP_ADDR_STRING
GatewayList.IP_ADDR_STRING
DhcpServer.IP_ADDR_STRING
HaveWins.l
PrimaryWinsServer.IP_ADDR_STRING
SecondaryWinsServer.IP_ADDR_STRING
LeaseObtained.l
LeaseExpires.l
EndStructure
length.l=0
result=GetAdaptersInfo_(0,@length) ; Get the length for Buffer
If result=#ERROR_BUFFER_OVERFLOW
*Buffer=AllocateMemory(length)
result=GetAdaptersInfo_(*Buffer,@length)
If result=#ERROR_SUCCESS
adapters=length/SizeOf(IP_ADAPTER_INFO)
For x=0 To adapters-1
Debug "AdapterNr : "+Str(x+1)
tempipinfo.IP_ADAPTER_INFO
For i=0 To SizeOf(IP_ADAPTER_INFO)-1
byte.b=PeekB(*Buffer+(x*640)+i)
PokeB(tempipinfo+i,byte)
Next
; ***** added by Sparkie*****************
keyRead.l = 0
connectionName$ = Space(255)
datasize.l = 255
myConnections$ = PeekS(@tempipinfo\AdapterName)
myKey$ = "SYSTEM\CurrentControlSet\Control\Network\{4D36E972-E325-11CE-BFC1-08002BE10318}\" + myConnections$ + "\Connection"
RegOpenKeyEx_(#HKEY_LOCAL_MACHINE, myKey$, 0, #KEY_READ, @keyRead)
RegQueryValueEx_(keyRead, "Name", 0, 0, @connectionName$, @datasize)
RegCloseKey_(keyRead)
Debug "Connection Name : "+connectionName$
; *****************************************
Debug "Adapter : "+PeekS(@tempipinfo\Description)
Debug "IP-Adress : "+PeekS(@tempipinfo\IpAddressList+4)
Debug "Gateway : "+PeekS(@tempipinfo\GatewayList+4)
mac$=""
For i=0 To 5
byte.b=PeekB(@tempipinfo\Address+i)
If byte>=0
mac$+RSet(Hex(byte),2,"0")
Else
mac$+RSet(Hex(byte+256),2,"0")
EndIf
If i<5
mac$+":"
EndIf
Next
Debug "MAC-Address "+mac$
Next
Else
Debug "Error : "+Str(result)
EndIf
EndIf
;----- Sample dump------------------------------------------------------------------
;AdapterNr : 1
;Connection Name : My Lan
;Adapter : ELSA Airlancer MC11 High Rate Wireless LAN PC Card - Paketplaner-Miniport
;IP-Adress : 192.168.1.115
;Gateway : 192.168.1.1
;MAC-Address 00:02:2D:3C:2E:73
;AdapterNr : 2
;Adapter : Realtek RTL8139-Familie-PCI-Fast Ethernet-NIC - Paketplaner-Miniport
;IP-Adress : 0.0.0.0
;Gateway :
;MAC-Address 00:30:54:00:40:63
** edited to fix error found by PB **