Starstar Posted November 14, 2013 Share Posted November 14, 2013 (edited) 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 November 14, 2013 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." Link to comment Share on other sites More sharing options...
mrflibblehat Posted November 14, 2013 Share Posted November 14, 2013 (edited) 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 November 14, 2013 by mrflibblehat [font="'courier new', courier, monospace;"]Pastebin UDF | Prowl UDF[/font] Link to comment Share on other sites More sharing options...
Starstar Posted November 14, 2013 Author Share Posted November 14, 2013 (edited) thanks a lot of you mrflibblehat i shall try. Edited November 14, 2013 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." Link to comment Share on other sites More sharing options...
Starstar Posted November 14, 2013 Author Share Posted November 14, 2013 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." Link to comment Share on other sites More sharing options...
mrflibblehat Posted November 15, 2013 Share Posted November 15, 2013 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] Link to comment Share on other sites More sharing options...
dragan Posted November 15, 2013 Share Posted November 15, 2013 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: Link to comment Share on other sites More sharing options...
Starstar Posted November 15, 2013 Author Share Posted November 15, 2013 (edited) 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 November 21, 2013 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." Link to comment Share on other sites More sharing options...
Starstar Posted November 15, 2013 Author Share Posted November 15, 2013 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." Link to comment Share on other sites More sharing options...
Starstar Posted November 15, 2013 Author Share Posted November 15, 2013 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." Link to comment Share on other sites More sharing options...
Moderators JLogan3o13 Posted November 15, 2013 Moderators Share Posted November 15, 2013 Adnonbalach, as always, you want people to guess at what you're trying to do. We need a little more than "doesn't work". "Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball How to get your question answered on this forum! Link to comment Share on other sites More sharing options...
Starstar Posted November 15, 2013 Author Share Posted November 15, 2013 (edited) 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 November 15, 2013 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." Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now