Jump to content

How to get list of ALL network adapters?


Recommended Posts

Try this:

#include <Array.au3>
$sHost = @ComputerName
$aNetworkAdapters = WMI_ListAllNetworkAdapters($sHost)

_ArrayDisplay($aNetworkAdapters)

Func WMI_ListAllNetworkAdapters($sHost) ;coded by UEZ 2013
    Local $objWMIService = ObjGet("winmgmts:\\" & $sHost & "\root\cimv2")
    If @error Then Return SetError(1, 0, 0)
    Local $aStatus[13] = ["Disconnected", "Connecting", "Connected", "Disconnecting", "Hardware not present", "Hardware disabled", "Hardware malfunction", _
                          "Media Disconnected", "Authenticating", "Authentication Succeeded", "Authentication Failed", "Invalid Address", "Credentials Required"]
    $colItems = $objWMIService.ExecQuery("SELECT Name, NetConnectionID, NetConnectionStatus FROM Win32_NetworkAdapter", "WQL", 0x30)
    Local $aNetworkAdapters[1000][3], $i = 0, $iPointer
    If IsObj($colItems) Then
        For $objItem in $colItems
            With $objItem
                $aNetworkAdapters[$i][0] = .NetConnectionID
                $aNetworkAdapters[$i][1] = .Name
                $aNetworkAdapters[$i][2] = $aStatus[.NetConnectionStatus * 1]
            EndWith
            $i += 1
        Next
        ReDim $aNetworkAdapters[$i][3]
        Return $aNetworkAdapters
    Else
        Return SetError(2, 0, 0)
    EndIf
EndFunc

Br,

UEZ

Edited by UEZ

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Link to comment
Share on other sites

Try this:

#include <Array.au3>
$sHost = @ComputerName
$aNetworkAdapters = WMI_ListAllNetworkAdapters($sHost)

_ArrayDisplay($aNetworkAdapters)

Func WMI_ListAllNetworkAdapters($sHost) ;coded by UEZ 2013
Local $objWMIService = ObjGet("winmgmts:\\" & $sHost & "\root\cimv2")
If @error Then Return SetError(1, 0, 0)
$colItems = $objWMIService.ExecQuery("SELECT Name, NetConnectionID FROM Win32_NetworkAdapter WHERE NetConnectionStatus IS NOT NULL", "WQL", 0x30)
Local $aNetworkAdapters[1000][2], $i = 0
If IsObj($colItems) Then
For $objItem in $colItems
With $objItem
$aNetworkAdapters[$i][0] = .NetConnectionID
$aNetworkAdapters[$i][1] = .Name
EndWith
$i += 1
Next
ReDim $aNetworkAdapters[$i][2]
Return $aNetworkAdapters
Else
Return SetError(2, 0, 0)
EndIf
EndFunc

Br,

UEZ

Thanks, but it returns only connected adapters, but I need ALL, I tried also without "WHERE NetConnectionStatus IS NOT NULL", and it doesn't returns disconnected adapters.

_____________________________________________________________________________

Link to comment
Share on other sites

I've update the code from post#6. Please try it again. It can be that the NetConnectionID is empty. Check out for the name.

Br,

UEZ

Edited by UEZ

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Link to comment
Share on other sites

I've update the code from post#6. Please try it again. It can be that the NetConnectionID is empty. Check out for the name.

Thanks, but it doesn't returns my disconected ppp(modem) adapters. Code return's only names of local connections.. Edited by GodlessSinner

_____________________________________________________________________________

Link to comment
Share on other sites

$objWMIService = ObjGet("winmgmts:\\.\root\cimv2")
If Not IsObj($objWMIService) Then
    MsgBox(0,"Error","$objWMIService Not Object")
    Exit
EndIf
$sQuery = "Select * from Win32_NetworkAdapter"
$colItems = $objWMIService.ExecQuery ($sQuery)
If Not IsObj($colItems) Then
    MsgBox(0,"Error","$objWMIService Not Object")
    Exit
EndIf
;MsgBox(0,0,VarGetType($colItems))
$sResult = ""
$count = 0
For $objItem In $colItems
    $count += 1

    ;$sResult &= "Index: " & $objItem.WINSScopeID & @CRLF
    ;$sResult &= "Caption: " & $objItem.Caption & @CRLF
    ;ConsoleWrite("> " & $sResult)
    $sResult &= "Name: " & $objItem.Name & @CRLF
    $sResult &= "Description: " & $objItem.Description & @CRLF
    ;ConsoleWrite("> " & $sResult)
    $sResult &= "MACAddress: " & $objItem.MACAddress & @CRLF
    ;ConsoleWrite("> " & $sResult)
    $sResult &= "NetConnectionStatus: " & $objItem.NetConnectionStatus & @CRLF
    ;ConsoleWrite("> " & $sResult)
    $sResult &= "GUID: " & $objItem.GUID & @CRLF
    ;For $strIPAddress In $objItem.IPAddress
    ;    $sResult &= "IPAddress: " & $strIPAddress & @CRLF
    ;Next
    $sResult &= @CRLF
Next
ConsoleWrite("There are " & $count & " devices available" & @LF & @LF)
ConsoleWrite($sResult & @LF)

AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Link to comment
Share on other sites

Your code doesn't returns even connected internet(modem) adapters.

It's seems impossible in C# and AutoIt and it can't be done via registry.

Edited by GodlessSinner

_____________________________________________________________________________

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...