chivas01 Posted February 23, 2009 Share Posted February 23, 2009 I'm trying to put together a script that will automatically disable the wireless card when an ethernet connected is made and then re enable the wireless when the ethernet is disconnected. Any help would be appreciated. Link to comment Share on other sites More sharing options...
exodius Posted February 23, 2009 Share Posted February 23, 2009 You might want to start here. Link to comment Share on other sites More sharing options...
chivas01 Posted February 25, 2009 Author Share Posted February 25, 2009 You might want to start here.Thank you for the response. However, I have already looked into the devcon utility and i am able to write a script that will disable the wireless and enable via command line and/or app script. What i'm looking for (and unable to do) is a way to have a script detect whether a lan connection is present or not...meaning, detect whether the ethernet cable is plugged or unplugged and be able to return a TRUE or FALSE. I have been trying to find how windows xp detirmines this, but using devcon and ipconfig, the ethernet adapter is always coming back active. There are many applications available that do this task, but i'm trying to find the code or script that detects it and from there will disable or enable the wireless. Link to comment Share on other sites More sharing options...
exodius Posted February 25, 2009 Share Posted February 25, 2009 (edited) Then your Googling must become stronger!http://msdn.microsoft.com/en-us/library/aa394216(VS.85).aspxhttp://www.microsoft.com/technet/scriptcen...08/hey0908.mspxhttp://www.issociate.de/board/index.php?t=...amp;goto=447028And maybe more here. Edited February 25, 2009 by exodius Link to comment Share on other sites More sharing options...
Moderators JLogan3o13 Posted July 27, 2010 Moderators Share Posted July 27, 2010 (edited) I know this is quite an old topic to resurrect, but I recently found myself looking for the same information. I've since completed a purely AutoIT script that does the job for about 20 laptops, and thought I'd share. Hopefully this will make it easier for the next person.. Assumes there are only two adapters, the LAN and Wireless... #include <File.au3> #NoTrayIcon While 1 $IP = @IPAddress1 If $IP = "127.0.0.1" Then Run('c:\WINDOWS\System32\cmd.exe' & ' /c sc query WZCSVC | find "STATE" > C:\state.txt', "", @SW_HIDE) Sleep( 5000 ) $file = "c:\state.txt" FileOpen($file, 0) $line = FileReadLine($file, 1) $state = StringTrimLeft(StringTrimRight($line, 1), 32) If $state <> "RUNNING" Then Run('c:\WINDOWS\System32\cmd.exe' & ' /c net start WZCSVC', "", @SW_HIDE) Else Sleep( 10000 ) EndIf Else Run('c:\WINDOWS\System32\cmd.exe' & ' /c sc query WZCSVC | find "STATE" > C:\state.txt', "", @SW_HIDE) Sleep( 5000 ) $file = "c:\state.txt" FileOpen($file, 0) $line = FileReadLine($file, 1) $state = StringTrimLeft(StringTrimRight($line, 1), 32) If $state = "RUNNING" Then Run('c:\WINDOWS\System32\cmd.exe' & ' /c net stop WZCSVC', "", @SW_HIDE) Else Sleep( 10000 ) EndIf EndIf WEnd Edited July 27, 2010 by JLogan3o13 "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...
SublimePorte Posted July 28, 2010 Share Posted July 28, 2010 Here is a function I used in a login script to detect if the wireless card is being used via WMI, much cleaner way to do it: Func NetStatus($devid = 12) $objWMI = ObjGet("winmgmts:\\localhost\root\cimv2") $ifaces = $objWMI.ExecQuery("select * from win32_NetworkAdapter, "WQL", 0x10 + 0x20) For $iface in $ifaces If $iface.DeviceID == $devid Then Return $iface.NetConnectionStatus Next EndFunc I use the default value of 12 because that's the deviceid of my wireless card, but you can obviously pass it as a parameter yourself for your deviceid. Link to comment Share on other sites More sharing options...
omikron48 Posted July 28, 2010 Share Posted July 28, 2010 You can use a wmi query to return the ethernet adapters with a status value of connected from win32_networkadapters. Link to comment Share on other sites More sharing options...
AaronOoi Posted July 17, 2014 Share Posted July 17, 2014 I have my own way to do this: expandcollapse popup#include <File.au3> #include <Array.au3> #NoTrayIcon while 1 runwait(@ComSpec & ' /c for /F "tokens=1-10" %A in (''"netsh interface show interface | find /i "local""'') DO (echo %B %C %D %E %F %G) >> c:\temp\network.txt',"",@SW_HIDE) runwait(@ComSpec & ' /c for /F "tokens=1-10" %A in (''"netsh interface show interface | find /i "wireless""'') DO (echo %B %C %D %E %F %G) >> c:\temp\network.txt',"",@SW_HIDE) local $Network[10] _FileReadToArray("c:\temp\network.txt",$Network) $x = 1 $y = 1 Do if StringInStr($Network[$x],"Local") > 0 and StringInStr($Network[$x],"Connected",1) > 0 then ;if LAN is connected disable all wifi Do if StringInStr($Network[$y],"Wireless") > 0 and StringInStr($Network[$y],"Connected",1) > 0 Then ; if wireless and connected $Wireless_Name = StringReplace($Network[$y],"Connected Dedicated ","") runwait(@ComSpec & ' /c netsh interface set interface name="'&$Wireless_Name&'" disable',"",@SW_HIDE) EndIf $y += 1 Until $y = $Network[0]+1 EndIf if StringInStr($Network[$x],"Local") > 0 and StringInStr($Network[$x],"Disconnected",1) > 0 then Do if StringInStr($Network[$y],"Wireless") > 0 and StringInStr($Network[$y],"Disconnected",1) > 0 Then ; if wireless and disconnected $Wireless_Name = StringReplace($Network[$y],"Disconnected Dedicated ","") runwait(@ComSpec & ' /c netsh interface set interface name="'&$Wireless_Name&'" enable',"",@SW_HIDE) EndIf $y += 1 Until $y = $Network[0]+1 EndIf $x +=1 Until $x = $Network[0]+1 runwait(@ComSpec & ' /c del c:\temp\network.txt /f',"",@SW_HIDE) sleep(2000) WEnd Cyborg5000 1 Link to comment Share on other sites More sharing options...
Cyborg5000 Posted April 13, 2015 Share Posted April 13, 2015 (edited) I have my own way to do this: expandcollapse popup#include <File.au3> #include <Array.au3> #NoTrayIcon while 1 runwait(@ComSpec & ' /c for /F "tokens=1-10" %A in (''"netsh interface show interface | find /i "local""'') DO (echo %B %C %D %E %F %G) >> c:\temp\network.txt',"",@SW_HIDE) runwait(@ComSpec & ' /c for /F "tokens=1-10" %A in (''"netsh interface show interface | find /i "wireless""'') DO (echo %B %C %D %E %F %G) >> c:\temp\network.txt',"",@SW_HIDE) local $Network[10] _FileReadToArray("c:\temp\network.txt",$Network) $x = 1 $y = 1 Do if StringInStr($Network[$x],"Local") > 0 and StringInStr($Network[$x],"Connected",1) > 0 then ;if LAN is connected disable all wifi Do if StringInStr($Network[$y],"Wireless") > 0 and StringInStr($Network[$y],"Connected",1) > 0 Then ; if wireless and connected $Wireless_Name = StringReplace($Network[$y],"Connected Dedicated ","") runwait(@ComSpec & ' /c netsh interface set interface name="'&$Wireless_Name&'" disable',"",@SW_HIDE) EndIf $y += 1 Until $y = $Network[0]+1 EndIf if StringInStr($Network[$x],"Local") > 0 and StringInStr($Network[$x],"Disconnected",1) > 0 then Do if StringInStr($Network[$y],"Wireless") > 0 and StringInStr($Network[$y],"Disconnected",1) > 0 Then ; if wireless and disconnected $Wireless_Name = StringReplace($Network[$y],"Disconnected Dedicated ","") runwait(@ComSpec & ' /c netsh interface set interface name="'&$Wireless_Name&'" enable',"",@SW_HIDE) EndIf $y += 1 Until $y = $Network[0]+1 EndIf $x +=1 Until $x = $Network[0]+1 runwait(@ComSpec & ' /c del c:\temp\network.txt /f',"",@SW_HIDE) sleep(2000) WEnd Iam getting error as (22) : ==> Array variable has incorrect number of subscripts or subscript dimension range exceeded.: if StringInStr($Network[$y],"Wireless") > 0 and StringInStr($Network[$y],"Connected",1) > 0 Then if StringInStr(^ ERROR Edited April 13, 2015 by Cyborg5000 Link to comment Share on other sites More sharing options...
jchd Posted April 13, 2015 Share Posted April 13, 2015 netsh results are localized. Change searched strings for those your netsh returns. This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe hereRegExp tutorial: enough to get startedPCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta. SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt) Link to comment Share on other sites More sharing options...
Cyborg5000 Posted April 13, 2015 Share Posted April 13, 2015 netsh results are localized. Change searched strings for those your netsh returns. Iam using this with the help of above script RunWait (@ComSpec & ' /c for /F "tokens=1-10" %A in (''"netsh interface show interface | find /i "Connected""'') DO (echo %B %C %D %E %F %G) >> c:tempnetwork.txt',"") local $Network[10] _FileReadToArray("c:tempnetwork.txt",$Network) $x = 1 $y = 1 Do if StringInStr($Network[$x],"Local") > 0 and StringInStr($Network[$x],"Connected",1) > 0 then ;if LAN is connected disable all wifi Do if StringInStr($Network[$y],"Wireless") > 0 and StringInStr($Network[$y],"Connected",1) > 0 Then ; if wireless and connected $Wireless_Name = StringReplace($Network[$y],"Connected Dedicated ","") RunWait (@ComSpec & ' /c netsh interface set interface "Wireless Network Connection" admin=disable',"") EndIf $y += 1 Until $y = $Network[0]+1 EndIf Link to comment Share on other sites More sharing options...
jchd Posted April 13, 2015 Share Posted April 13, 2015 In a cmd shell, what does "netsh interface show interface" display? This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe hereRegExp tutorial: enough to get startedPCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta. SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt) Link to comment Share on other sites More sharing options...
Cyborg5000 Posted April 13, 2015 Share Posted April 13, 2015 In a cmd shell, what does "netsh interface show interface" display? C:WindowsSystem32>netsh interface show interface Admin State State Type Interface Name ------------------------------------------------------------------------- Disabled Disconnected Dedicated Cisco AnyConnect Secure Mobility Client Connection Disabled Disconnected Dedicated Wireless Network Connection Enabled Connected Dedicated Local Area Connection 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