Jump to content
Sign in to follow this  
Starstar

how can i check a network connection is exist or not in win7?

Recommended Posts

Starstar

how can i check a network connection is exist or not?

Please Guide me.i have not any idea.

In xp i use this.

$CONNECTION_NAME = "Your Connection name"
Run("control ncpa.cpl")
WinWait("Network Connections")
$ControlID = ControlListView("Network Connections", "", "SysListView321", "FindItem", $CONNECTION_NAME, "AACABLE - DIALER SERVICE")
If $ControlID <> -1 Then
$answer = MsgBox(0, "Connection Status","'"& $CONNECTION_NAME&"' is exist")
Endif

But in win 7 i completely confused... Please Help me. I really would be thankful to you.

Edited by adnanbaloch

Life is like a coin. You can spend it Anyway as you wish and for your kind information. "you can spend it only once."

Share this post


Link to post
Share on other sites
mrflibblehat

I would use WMI, Look at the Win32_NetworkAdapter Class (http://msdn.microsoft.com/en-us/library/aa394216(v=vs.85).aspx) and NetConnectionID field

I have quickly thrown this together, it shows if it exists.

$vConnection = "Local Area Connection"

$vServices = ObjGet("winmgmts:\\" & @ComputerName & "\root\CIMV2")
$vNetConf = $vServices.ExecQuery('SELECT * FROM Win32_NetworkAdapter')
For $vFields In $vNetConf
    If $vFields.NetConnectionID = $vConnection Then
        ConsoleWrite("Connection Exists" & @CRLF & $vFields.NetConnectionID & @CRLF)
    EndIf
Next
Edited by mrflibblehat

[font="'courier new', courier, monospace;"]Pastebin UDF | Prowl UDF[/font]

Share this post


Link to post
Share on other sites
Starstar

thanks a lot of you mrflibblehat i shall try.

Edited by adnanbaloch

Life is like a coin. You can spend it Anyway as you wish and for your kind information. "you can spend it only once."

Share this post


Link to post
Share on other sites
Starstar

Thanks mrflibblehat. It works but when i try to check an pppoe account(WAN mini port) it fails. Please Gide me more..........


Life is like a coin. You can spend it Anyway as you wish and for your kind information. "you can spend it only once."

Share this post


Link to post
Share on other sites
mrflibblehat

Thanks mrflibblehat. It works but when i try to check an pppoe account(WAN mini port) it fails. Please Gide me more..........

as I dont have a WAN Mini Port to try it out on I cant test any code, but It would be worth having a look in Win32_NetworkAdapteConfiguration WMI Class


[font="'courier new', courier, monospace;"]Pastebin UDF | Prowl UDF[/font]

Share this post


Link to post
Share on other sites
dragan

is this working?

 

#RequireAdmin
#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

Coded by: UEZ
Source:

Share this post


Link to post
Share on other sites
Starstar

I tried like this but i could not get success.

$vConnection = "BB-LINK"

$wbemFlagReturnImmediately = 0x10
$wbemFlagForwardOnly = 0x20
$colItems = ""
$strComputer = "localhost"

$Output=""
$Output = $Output & "Computer: " & $strComputer  & @CRLF
$Output = $Output & "==========================================" & @CRLF
$objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\ROOT\CIMV2")
$colItems = $objWMIService.ExecQuery("SELECT * FROM Win32_NetworkAdapterConfiguration", "WQL", _
                                          $wbemFlagReturnImmediately + $wbemFlagForwardOnly)

For $vFields In $colItems
     If $vFields.ServiceName= $vConnection Then
        ConsoleWrite("Connection Exists" & @CRLF & $vFields.ServiceName & @CRLF)
    EndIf
Next
Edited by Starstar

Life is like a coin. You can spend it Anyway as you wish and for your kind information. "you can spend it only once."

Share this post


Link to post
Share on other sites
Starstar

is this working?

 

#RequireAdmin
#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

Coded by: UEZ

Source:

I shall try.Thanks a lot of you........


Life is like a coin. You can spend it Anyway as you wish and for your kind information. "you can spend it only once."

Share this post


Link to post
Share on other sites
Starstar

No dragan.....it is not for me......


Life is like a coin. You can spend it Anyway as you wish and for your kind information. "you can spend it only once."

Share this post


Link to post
Share on other sites
JLogan3o13

Adnonbalach, as always, you want people to guess at what you're trying to do. We need a little more than "doesn't work".


√-1 2^3 ∑ π, and it was delicious!

Share this post


Link to post
Share on other sites
Starstar

Welcome JLogan3o13. I created a script that can create PPPoE login account automaticaly. But i need to check that is Network connection already exist or not? before run the script. Becuse in windows dublicate account is not allowed.

Edited by Starstar

Life is like a coin. You can spend it Anyway as you wish and for your kind information. "you can spend it only once."

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  

×