Jump to content
Sign in to follow this  

[Solved] Detect LAN speed

Recommended Posts


Hi, I am trying to make script that detects the actual speed of my Wlan - it sometimes stucks on 5.5 Mbits and i have to reconnect to wlan to get the full speed again.

I've been searching quite long for func that can retrieve the information - without success.

Now I found some function on MSDN that should be able to return the speed - MultinetGetConnectionPerformance.

The point is that the function requires input from another function and that from another function, ... and so I got lost. I really dont know how to continue so I would be glad if somebody gives me a helping hand.

;typedef struct _NETRESOURCE {DWORD  dwScope;DWORD  dwType;DWORD  dwDisplayType;DWORD  dwUsage;LPTSTR lpLocalName;LPTSTR lpRemoteName;LPTSTR lpComment;  LPTSTR lpProvider;
Local $NETRESOURCESTRUCT    = DllStructCreate('dword;dword;dword;dword;str;str;str;str')

;typedef struct _NETCONNECTINFOSTRUCT { DWORD cbStructure;  DWORD dwFlags;  DWORD dwSpeed;  DWORD dwDelay;  DWORD dwOptDataSize;
Local $NETCONNECTINFOSTRUCT = DllStructCreate('dword cbStructure;dword dwFlags;dword dwSpeed;dword dwDelay;dword deOptDataSize')

  __in   HANDLE hEnum,
  __inout  LPDWORD lpcCount,
  __out LPVOID lpBuffer,
  __inout  LPDWORD lpBufferSize
DllCall('Mpr.dll', 'dword', 'WNetEnumResource', 'ptr', $hEnum, 'dword*', $lpcCount, 'ptr', $lpBuffer, 'dword*', $lpBufferSize)

; http://msdn.microsoft.com/en-us/library/aa385342(VS.85).aspx
DllCall('Mpr.dll', 'dword', 'MultinetGetConnectionPerformance', 'ptr', DllStructGetPtr($NETRESOURCESTRUCT), 'ptr', DllStructGetPtr($NETCONNECTINFOSTRUCT))

MsgBox(0, '', DllStructGetData($NETCONNECTINFOSTRUCT, 'dwSpeed'))
Edited by Markos

Share this post

Link to post
Share on other sites


Share this post

Link to post
Share on other sites

Try out my Performance Counters UDF, see if there's something there you can use - its in my signature.

I recommend trying the 'TestPDH_PerformanceCounters' function and going to 'Manual Entry' (after the initial selection box - which you can't bypass currently, so select anything and go to the next screen) and enter this:

\Network Interface(*)\*

If you have multiple cards, it will list them all, but you can adjust it for the card you want to look at (the wildcard in parentheses should be modified).

Hope maybe that helps *shrug*

Edited by ascendant

Share this post

Link to post
Share on other sites

Why not time how long it takes to download a small-ish file by FTP or HTTP? MultinetGetConnectionPerformance is only making a guess based on recent throughput so this method would probably be just as reliable ...


Share this post

Link to post
Share on other sites

So I have finally took deeper look into ascendant's functions.

Thank you - your funcs are gr8 piece of work, that is exactly what I was looking for.

If anybody is interested in what I was trying to accomplish - here is the code:

#include "_PDH_PerformanceCounters.au3"
#include "Native_Wifi_Func_V2_1.au3"

Local  $sObject = '\Rozhraní sítě(Bezdrátová dvoupásmová minikarta Dell 1490 WLAN)\Aktuální šířka pásma'
Global $sSSID   = 'Mi-Fi'
Global $iRecheckTime = 60000
Global $iReconnectIfLowerThan = 5500000

Global $hPDH_QueryHandle    = _PDH_GetNewQueryHandle()
Global $hPDH_CounterHandle  = _PDH_AddCounter($hPDH_QueryHandle, $sObject)
Global $hClientHandle       = _Wlan_OpenHandle()
Global $pGUID               = _Wlan_EnumInterfaces($hClientHandle)

Global $aInterfaceRes
While 1
    $aInterfaceRes = _Wlan_QueryInterface($hClientHandle, $pGUID[0][0], 3)
;~  If Not IsArray($aInterfaceRes) ThenConsoleWrite('Disconnected' & @CRLF)

    If IsArray($aInterfaceRes) And $aInterfaceRes[1] = $sSSID And _PDH_UpdateCounter($hPDH_QueryHandle,$hPDH_CounterHandle) <= $iReconnectIfLowerThan Then
        _Wlan_Disconnect($hClientHandle, $pGUID[0][0])
        _Wlan_Connect($hClientHandle, $pGUID[0][0], $sSSID)


Func OnAutoItExit()

Share this post

Link to post
Share on other sites

Glad I could help, not quite sure what Counter you are using (don't understand that language) - but you forgot an important part of the code - _PDH_Init(). That should be called prior to getting new Query Handles. It will prevent the Query Handles & Counter Handles from returning constant errors.

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this