WinBatch Tech Support Home

Database Search

If you can't find the information using the categories below, post a question over in our WinBatch Tech Support Forum.

TechHome

WMI
plus
plus

Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.

Detecting Local Network Connectivity and Speed

 Keywords:  Detecting Local Network Connectivity and Speed LAN Adapter

Question:

In Windows XP, is there any way to either capture or get the value of the speed of the network? You see this when you enable the "show icon on taskbar when connected" option. When you pass the cursor over the systray icon a balloon displays "Local Area Connection Speed: 10.0 Mbps", or if you double-click on it and look at "Local Area Connection Status" window it shows the info I need to capture. I tried WMI but got nowhere.

Answer:

Give this code a try:
Locator = ObjectOpen("WbemScripting.SWbemLocator")
CIMService = Locator.ConnectServer("", "root/cimv2")
WMIService = Locator.ConnectServer("", "root/wmi")
WQL = "Select * From Win32_NetworkAdapterConfiguration Where DatabasePath IS NOT NULL"
NetworkAdapters = CIMService.ExecQuery(WQL)
hEnum = ObjectCollectionOpen(NetworkAdapters)
While 1
   Adapter = ObjectCollectionNext(hEnum)
   If Adapter == 0 Then Break
   Cap = Adapter.Caption
   ;Parse string by removing leading [xxxxxxx]
   AdapterName = StrSub(Cap, StrIndex(Cap, "]", 0, @FWDSCAN)+2,-1)
	LinkSpeedClass = "MSNDIS_LinkSpeed"
	SpeedInstance = WMIService.InstancesOf(LinkSpeedClass)
	SpeedhEnum = ObjectCollectionOpen(SpeedInstance)
	While 1
	  SpeedObj = ObjectCollectionNext(SpeedhEnum)
	  if SpeedObj == 0 Then Break
	  AdapterName2 = SpeedObj.InstanceName
	  if AdapterName==AdapterName2
		  Speed = SpeedObj.NDISLinkSpeed/10 ;kbps
		  Message(StrCat("Instance name"," = ",AdapterName),StrCat("NDISLinkSpeed = ",Speed, " kbps"))
			if (SpeedObj.Active == -1)
			  Message("Active:","Yes")
			else
			  Message("Active:","No")
			endIf
		endif
		ObjectClose(SpeedObj)
	EndWhile
	ObjectCollectionClose(SpeedhEnum)
	ObjectClose(SpeedInstance)
	ObjectClose(Adapter)
EndWhile
ObjectCollectionClose(hEnum)
ObjectClose(NetworkAdapters)
ObjectClose(WMIService)
ObjectClose(CIMService)
ObjectClose(Locator)
exit

Article ID:   W15783
File Created: 2005:05:12:08:46:20
Last Updated: 2005:05:12:08:46:20