Mukhtar Posted August 8, 2010 Posted August 8, 2010 Dear Professionals, I need an AutoIt Script to see if there are two active network connections ( Local Area Network and Wireless Network Connection ) then it should disable wireless network by default. I have searched the whole internet but I couldn't find such a script. Then I stumbled upon AutoIt. I searched AutoIt Forums and found the script to disable the network adapter. I just need a simple condition to check the active network connections (local area network and wireless network connection) then I can run the below script to disable the wireless network connection by default. If the user has only 1 active network adaptor connection then it should do nothing. expandcollapse popup; Disable and Enable a Network card using 'Shell.Application' ; ; See also: http://blog.mvpcn.net/icuc88/articles/244.aspx ; ; To do: Rewrite this into a UDF. Parameters: $oLanConnection and $bEnabled $oLanConnection = "Local Area Connection"; Change this to the name of the adapter to be disabled ! $bEnable = False ; Change this to 'false' to DISABLE the network adapter if @OSType<>"WIN32_NT" then Msgbox(0,"","This script requires Windows 2000 or higher.") exit endif if @OSVersion="WIN_2000" then $strFolderName = "Network and Dial-up Connections" else $strFolderName = "Network Connections"; Windows XP endif Select Case StringInStr("0409,0809,0c09,1009,1409,1809,1c09,2009,2409,2809,2c09,3009,3409", @OSLang) ; English (United States) $strEnableVerb = "En&able" $strDisableVerb = "Disa&ble" ; Add here the correct Verbs for your Operating System Language EndSelect ;Virtual folder containing icons for the Control Panel applications. (value = 3) Const $ssfCONTROLS = 3 $ShellApp = ObjCreate("Shell.Application") $oControlPanel = $shellApp.Namespace($ssfCONTROLS) ; Find 'Network connections' control panel item $oNetConnections="" For $FolderItem in $oControlPanel.Items If $FolderItem.Name = $strFolderName then $oNetConnections = $FolderItem.GetFolder Exitloop Endif Next If not IsObj($oNetConnections) Then MsgBox(0,"Error","Couldn't find " & $strFolderName & " folder." ) Exit EndIf For $FolderItem In $oNetConnections.Items If StringLower($FolderItem.Name) = StringLower($oLanConnection) Then $oLanConnection = $FolderItem Exitloop EndIf Next If not IsObj($oLanConnection) Then MsgBox(0,"Error","Couldn't find " & $oLanConnection & " Item." ) Exit EndIf $oEnableVerb="" $oDisableVerb="" For $Verb In $oLanConnection.Verbs If $Verb.Name = $strEnableVerb Then $oEnableVerb = $Verb EndIf If $Verb.Name = $strDisableVerb Then $oDisableVerb = $Verb EndIf Next If $bEnable then If IsObj($oEnableVerb) Then $oEnableVerb.DoIt ; Enable network card Endif If not $bEnable then If IsObj($oDisableVerb) Then $oDisableVerb.DoIt; Disable network card EndIf Msgbox(0,"","Your local area network has been disabled") Sleep(1000) I will really appreciate. I am eagerly looking forward for your prompt replies and co-operation.
Mukhtar Posted August 9, 2010 Author Posted August 9, 2010 bumping the thread in the hope to get a reply.. anyone have any idea? if u need more explanation please let me know.
UEZ Posted August 9, 2010 Posted August 9, 2010 I don't know whether this will help you: expandcollapse popup;Coded by UEZ 2009 #AutoIt3Wrapper_Change2CUI=y #AutoIt3Wrapper_UseUpx=n Global $ip = "localhost" If $CmdLine[0] > 0 Then $ip = $CmdLine[1] $objWMIService = ObjGet("winmgmts:{impersonationLevel = impersonate}!\\" & $ip & "\root\cimv2") GetWMI($ip) Func GetWMI($srv) Local $Net_Description, $colItems, $colItem, $ping, $x $ping = Ping($srv) If $ping Then $colItems = $objWMIService.ExecQuery("SELECT Description FROM Win32_NetworkAdapterConfiguration WHERE IPEnabled = True", "WQL", 0x00).Count If $colItems > 1 Then $colItems = $objWMIService.ExecQuery("SELECT Description FROM Win32_NetworkAdapterConfiguration WHERE IPEnabled = True", "WQL", 0x30) If IsObj($colItems) Then For $objItem In $colItems $Net_Description &= $objItem.Description & @CRLF Next SetError(0) MsgBox(0, "Network Adapter Information", "More than 1 enabled network adapters found: " & @CRLF & @CRLF & $Net_Description) Return $Net_Description Else SetError(1) Return "Error!" EndIf Else MsgBox(0, "Information", "Only one network adapter found") EndIf Else SetError(1) Return "Host not reachable" EndIf EndFunc Br, 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!¯\_(ツ)_/¯ ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ
Mukhtar Posted August 9, 2010 Author Posted August 9, 2010 Thank you so much UEZ this is very close to what I need. I was wondering if you could please kindly help me and modify the code to check if local area connection and wireless network connection are active/enabled then I can use the above script to disable the wireless network connection. Since you're a professional it will take you just few minutes and I will really appreciate it.Looking forward for your help.
UEZ Posted August 9, 2010 Posted August 9, 2010 And what about this version:expandcollapse popup;Coded by UEZ 2009 #AutoIt3Wrapper_Change2CUI=y #AutoIt3Wrapper_UseUpx=n Global $ip = "localhost" If $CmdLine[0] > 0 Then $ip = $CmdLine[1] $objWMIService = ObjGet("winmgmts:{impersonationLevel = impersonate}!\\" & $ip & "\root\cimv2") GetWMI($ip) Func GetWMI($srv) Local $Net_Description, $colItems, $colItem, $ping, $msg $ping = Ping($srv) If $ping Then If $objWMIService.ExecQuery("SELECT Description FROM Win32_NetworkAdapterConfiguration WHERE IPEnabled = True", "WQL", 0x00).Count > 1 Then $colItems = $objWMIService.ExecQuery("SELECT Description FROM Win32_NetworkAdapterConfiguration WHERE IPEnabled = True", "WQL", 0x30) If IsObj($colItems) Then For $objItem In $colItems $Net_Description &= $objItem.Description & @CRLF Next SetError(0) $msg = "More than one enabled network adapter found: " & @CRLF & @CRLF & $Net_Description & @CRLF If StringInStr($Net_Description, "Wireless Network Connection") > 0 Then MsgBox(0, "Network Adapter Information", $msg & "Wireless Network Connection can be disabled") Else MsgBox(0, "Network Adapter Information", $msg) EndIf Return $Net_Description Else SetError(1) Return "Error!" EndIf Else MsgBox(0, "Information", "Only one network adapter found") EndIf Else SetError(1) Return "Host not reachable" EndIf EndFuncBr,UEZPS: I'm far away being a professional! 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!¯\_(ツ)_/¯ ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ
Mukhtar Posted August 10, 2010 Author Posted August 10, 2010 (edited) It works awesome!... after i made a small change, replaced "Wireless Network Connection" with "Dell Wireless 1397 WLAN Mini-Card" because it's comparing against the description of the network card. expandcollapse popup;Coded by UEZ 2009 #AutoIt3Wrapper_Change2CUI=y #AutoIt3Wrapper_UseUpx=n Global $ip = "localhost" If $CmdLine[0] > 0 Then $ip = $CmdLine[1] $objWMIService = ObjGet("winmgmts:{impersonationLevel = impersonate}!\\" & $ip & "\root\cimv2") GetWMI($ip) Func GetWMI($srv) Local $Net_Description, $colItems, $colItem, $ping, $msg $ping = Ping($srv) If $ping Then If $objWMIService.ExecQuery("SELECT Description FROM Win32_NetworkAdapterConfiguration WHERE IPEnabled = True", "WQL", 0x00).Count > 1 Then $colItems = $objWMIService.ExecQuery("SELECT Description FROM Win32_NetworkAdapterConfiguration WHERE IPEnabled = True", "WQL", 0x30) If IsObj($colItems) Then For $objItem In $colItems $Net_Description &= $objItem.Description & @CRLF Next SetError(0) $msg = "More than one enabled network adapter found: " & @CRLF & @CRLF & $Net_Description & @CRLF If StringInStr($Net_Description, "Dell Wireless 1397 WLAN Mini-Card") > 0 Then MsgBox(0, "Network Adapter Information", $msg & "Wireless Network Connection can be disabled") Else MsgBox(0, "Network Adapter Information", $msg) EndIf Return $Net_Description Else SetError(1) Return "Error!" EndIf Else MsgBox(0, "Information", "Only one network adapter found") EndIf Else SetError(1) Return "Host not reachable" EndIf EndFunc There is a problem I can't use the above script because every user has a different Wireless LAN Card. I need to compare against the NetconnectionID. for this I made changes in the below line. For $objItem In $colItems $Net_Description &= $objItem.NetConnectionID& @CRLF NextIt didn't work and gave me an error message Could you please kindly look into this once again?? Can we compare against the NetConnectionID and not the description?? forexample: "Wireless Network Connection" and not Dell Wireless 1397 WLAN Mini-Card. Thanks alot once again! Please let me know if you have any question or need more explanation. Edited August 10, 2010 by Mukhtar
omikron48 Posted August 10, 2010 Posted August 10, 2010 (edited) You can query using AdapterTypeID from Win32_NetworkAdapter class to differentiate the types of network adapters that are active. Edited August 10, 2010 by omikron48
Mukhtar Posted August 10, 2010 Author Posted August 10, 2010 (edited) You can query using AdapterTypeID from Win32_NetworkAdapter class to differentiate the types of network adapters that are active. Thank you omikron48 however unfortunately im not a programmer. If you could please kindly modify UEZ's code I will really appreciate. expandcollapse popup;Coded by UEZ 2009 #AutoIt3Wrapper_Change2CUI=y #AutoIt3Wrapper_UseUpx=n Global $ip = "localhost" If $CmdLine[0] > 0 Then $ip = $CmdLine[1] $objWMIService = ObjGet("winmgmts:{impersonationLevel = impersonate}!\\" & $ip & "\root\cimv2") GetWMI($ip) Func GetWMI($srv) Local $Net_Description, $colItems, $colItem, $ping, $msg $ping = Ping($srv) If $ping Then If $objWMIService.ExecQuery("SELECT Description FROM Win32_NetworkAdapterConfiguration WHERE IPEnabled = True", "WQL", 0x00).Count > 1 Then $colItems = $objWMIService.ExecQuery("SELECT Description FROM Win32_NetworkAdapterConfiguration WHERE IPEnabled = True", "WQL", 0x30) If IsObj($colItems) Then For $objItem In $colItems $Net_Description &= $objItem.Description & @CRLF Next SetError(0) $msg = "More than one enabled network adapter found: " & @CRLF & @CRLF & $Net_Description & @CRLF If StringInStr($Net_Description, "Dell Wireless 1397 WLAN Mini-Card") > 0 Then MsgBox(0, "Network Adapter Information", $msg & "Wireless Network Connection can be disabled") Else MsgBox(0, "Network Adapter Information", $msg) EndIf Return $Net_Description Else SetError(1) Return "Error!" EndIf Else MsgBox(0, "Information", "Only one network adapter found") EndIf Else SetError(1) Return "Host not reachable" EndIf EndFunc Edited August 10, 2010 by Mukhtar
omikron48 Posted August 10, 2010 Posted August 10, 2010 You gotta learn sometime... Put in some effort. This is a "help" section. If you didn't know, "help" doesn't mean we do all the work for you.
UEZ Posted August 10, 2010 Posted August 10, 2010 Here the modified version: expandcollapse popup;Coded by UEZ 2009 #AutoIt3Wrapper_Change2CUI=y #AutoIt3Wrapper_UseUpx=n Global $ip = "localhost" If $CmdLine[0] > 0 Then $ip = $CmdLine[1] $objWMIService = ObjGet("winmgmts:{impersonationLevel = impersonate}!\\" & $ip & "\root\cimv2") GetWMI($ip) Func GetWMI($srv) Local $Description, $NetConnectionID, $colItems, $colItem, $ping, $msg $ping = Ping($srv) If $ping Then If $objWMIService.ExecQuery("SELECT Description FROM Win32_NetworkAdapterConfiguration WHERE IPEnabled = True", "WQL", 0x00).Count > 1 Then $colItems = $objWMIService.ExecQuery("SELECT Description, NetConnectionID FROM Win32_NetworkAdapter WHERE NetConnectionStatus >= 0", "WQL", 0x30) If IsObj($colItems) Then For $objItem In $colItems $NetConnectionID &= $objItem.NetConnectionID & @CRLF $Description &= $objItem.Description & @CRLF Next SetError(0) $msg = "More than one enabled network adapter found: " & @CRLF & @CRLF & $Description & @CRLF If StringInStr($NetConnectionID, "Dell Wireless 1397 WLAN Mini-Card") > 0 Then MsgBox(0, "Network Adapter Information", $msg & "Dell Wireless 1397 WLAN Mini-Card can be disabled") Else MsgBox(0, "Network Adapter Information", $msg) EndIf Return $NetConnectionID Else SetError(1) Return "Error!" EndIf Else MsgBox(0, "Information", "Only one network adapter found") EndIf Else SetError(1) Return "Host not reachable" EndIf EndFunc I hope it works for you Br, 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!¯\_(ツ)_/¯ ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ
Mukhtar Posted August 16, 2010 Author Posted August 16, 2010 Thanks a Million @UEZ You Rock!!! You're one of the best programmers! Please check your PM, meanwhile please let me know if there is anything I can do for you.
Mariah Posted August 26, 2010 Posted August 26, 2010 Hi UEZ, this is exactly what ive been looking for... i found this forum after alot of searching. i put together the codes and made small change in the condition. you can see it below: expandcollapse popup;Coded by UEZ 2009 #AutoIt3Wrapper_Change2CUI=y #AutoIt3Wrapper_UseUpx=n Global $ip = "localhost" If $CmdLine[0] > 0 Then $ip = $CmdLine[1] $objWMIService = ObjGet("winmgmts:{impersonationLevel = impersonate}!\\" & $ip & "\root\cimv2") GetWMI($ip) Func GetWMI($srv) Local $Description, $NetConnectionID, $colItems, $colItem, $ping, $msg $ping = Ping($srv) If $ping Then If $objWMIService.ExecQuery("SELECT Description FROM Win32_NetworkAdapterConfiguration WHERE IPEnabled = True", "WQL", 0x00).Count > 1 Then $colItems = $objWMIService.ExecQuery("SELECT Description, NetConnectionID FROM Win32_NetworkAdapter WHERE NetConnectionStatus >= 0", "WQL", 0x30) If IsObj($colItems) Then For $objItem In $colItems $NetConnectionID &= $objItem.NetConnectionID & @CRLF $Description &= $objItem.Description & @CRLF Next SetError(0) $msg = "More than one enabled network adapter found: " & @CRLF & @CRLF & $NetConnectionID & @CRLF If (StringInStr($NetConnectionID, "Local Area Connection") > 0) AND (StringInStr($NetConnectionID, "Wireless Network Connection")> 0) Then MsgBox(0, "Network Adapter Information", $msg & "Wireless Network Connection can be disabled") ; Disable and Enable a Network card using 'Shell.Application' ; ; See also: http://blog.mvpcn.net/icuc88/articles/244.aspx ; ; To do: Rewrite this into a UDF. Parameters: $oLanConnection and $bEnabled $oLanConnection = "Wireless Network Connection"; Change this to the name of the adapter to be disabled ! $bEnable = False ; Change this to 'false' to DISABLE the network adapter if @OSType<>"WIN32_NT" then Msgbox(0,"","This script requires Windows 2000 or higher.") exit endif if @OSVersion="WIN_2000" then $strFolderName = "Network and Dial-up Connections" else $strFolderName = "Network Connections"; Windows XP endif Select Case StringInStr("0409,0809,0c09,1009,1409,1809,1c09,2009,2409,2809,2c09,3009,3409", @OSLang) ; English (United States) $strEnableVerb = "En&able" $strDisableVerb = "Disa&ble" ; Add here the correct Verbs for your Operating System Language EndSelect ;Virtual folder containing icons for the Control Panel applications. (value = 3) Const $ssfCONTROLS = 3 $ShellApp = ObjCreate("Shell.Application") $oControlPanel = $shellApp.Namespace($ssfCONTROLS) ; Find 'Network connections' control panel item $oNetConnections="" For $FolderItem in $oControlPanel.Items If $FolderItem.Name = $strFolderName then $oNetConnections = $FolderItem.GetFolder Exitloop Endif Next If not IsObj($oNetConnections) Then MsgBox(0,"Error","Couldn't find " & $strFolderName & " folder." ) Exit EndIf For $FolderItem In $oNetConnections.Items If StringLower($FolderItem.Name) = StringLower($oLanConnection) Then $oLanConnection = $FolderItem Exitloop EndIf Next If not IsObj($oLanConnection) Then MsgBox(0,"Error","Couldn't find " & $oLanConnection & " Item." ) Exit EndIf $oEnableVerb="" $oDisableVerb="" For $Verb In $oLanConnection.Verbs If $Verb.Name = $strEnableVerb Then $oEnableVerb = $Verb EndIf If $Verb.Name = $strDisableVerb Then $oDisableVerb = $Verb EndIf Next If $bEnable then If IsObj($oEnableVerb) Then $oEnableVerb.DoIt ; Enable network card Endif If not $bEnable then If IsObj($oDisableVerb) Then $oDisableVerb.DoIt; Disable network card EndIf Msgbox(0,"Wireless Disconnected, By default you'll be connected to LAN","You've been disconnected from Wireless Network Connection because you had more than 1 Network interface connected. If you want to use WLAN, please disconnect LAN cable and then connect WLan") ;Sleep(1000) Else MsgBox(0, "Network Adapter Information", $msg) EndIf Return $NetConnectionID Else SetError(1) Return "Error!" EndIf Else MsgBox(0, "Information", "Only one network adapter found") EndIf Else SetError(1) Return "Host not reachable" EndIf EndFunc and unfortunately it has 1 problem. It does not check if 2 NIC connected which means plugged in, then it should disable the WLAN. it only checks if 2 NIC enabled.. there is difference between enabled and being connected to 2 networks (LAN & WLAN)? Is it possible to check if it's connected to LAN and WLAN instead of checking for whether it's enabled? Can you help me guys pleasssseee?
UEZ Posted August 27, 2010 Posted August 27, 2010 Hi UEZ, this is exactly what ive been looking for... i found this forum after alot of searching. i put together the codes and made small change in the condition. You are welcome. and unfortunately it has 1 problem. It does not check if 2 NIC connected which means plugged in, then it should disable the WLAN. it only checks if 2 NIC enabled.. there is difference between enabled and being connected to 2 networks (LAN & WLAN)? Is it possible to check if it's connected to LAN and WLAN instead of checking for whether it's enabled? Can you help me guys pleasssseee? Try this code to get the Wireless Network Connection: ;Coded by UEZ 2009 #AutoIt3Wrapper_Change2CUI=y #AutoIt3Wrapper_UseUpx=n Global $ip = "localhost" If $CmdLine[0] > 0 Then $ip = $CmdLine[1] $objWMIService = ObjGet("winmgmts:{impersonationLevel = impersonate}!\\" & $ip & "\root\cimv2") GetWMI($ip) Func GetWMI($srv) Local $Description, $colItems, $colItem, $ping $ping = Ping($srv) If $ping Then $colItems = $objWMIService.ExecQuery("SELECT Description, NetConnectionID FROM Win32_NetworkAdapter WHERE NetConnectionID = 'Wireless Network Connection' And NetConnectionStatus > 0", "WQL", 0x30) If IsObj($colItems) Then For $objItem In $colItems MsgBox(0, "Wireless Network Adapter", $objItem.Description, 5) Next SetError(0) Else SetError(1) Return "Error!" EndIf Else SetError(1) Return "Host not reachable" EndIf EndFunc ;==>GetWMI This should list the network adapter "Wireless Network Connection" independently whether it has connection or not. You have to modify the NetConnectionID name appropriate your NetConnectionID! In my case it is "Wireless Network Connection". Currently I don't know how to disabled the WLAN adapter on OS Vista+ using WMI or Shell objects (I have never needed it!). BR, 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!¯\_(ツ)_/¯ ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ
Mariah Posted August 29, 2010 Posted August 29, 2010 Thank you UEZ for replying.. This should list the network adapter "Wireless Network Connection" independently whether it has connection or not.I checked and It listed the network adapter whether it is enabled or not.I want whether it is connected to the network or not.I need a Condition to check if Local Area Connection and Wireless Area Connection both are connected to the network.Thanks for your time in advance please let me know if u have any confusion and/or need anything.
Mariah Posted August 31, 2010 Posted August 31, 2010 I just changed the NetConnectionStatus=2 and dat solved my problem.. thanks again UEZ no need to reply now
joe1981al Posted October 14, 2010 Posted October 14, 2010 You are welcome. Try this code to get the Wireless Network Connection: ;Coded by UEZ 2009 #AutoIt3Wrapper_Change2CUI=y #AutoIt3Wrapper_UseUpx=n Global $ip = "localhost" If $CmdLine[0] > 0 Then $ip = $CmdLine[1] $objWMIService = ObjGet("winmgmts:{impersonationLevel = impersonate}!\\" & $ip & "\root\cimv2") GetWMI($ip) Func GetWMI($srv) Local $Description, $colItems, $colItem, $ping $ping = Ping($srv) If $ping Then $colItems = $objWMIService.ExecQuery("SELECT Description, NetConnectionID FROM Win32_NetworkAdapter WHERE NetConnectionID = 'Wireless Network Connection' And NetConnectionStatus > 0", "WQL", 0x30) If IsObj($colItems) Then For $objItem In $colItems MsgBox(0, "Wireless Network Adapter", $objItem.Description, 5) Next SetError(0) Else SetError(1) Return "Error!" EndIf Else SetError(1) Return "Host not reachable" EndIf EndFunc ;==>GetWMI This should list the network adapter "Wireless Network Connection" independently whether it has connection or not. You have to modify the NetConnectionID name appropriate your NetConnectionID! In my case it is "Wireless Network Connection". Currently I don't know how to disabled the WLAN adapter on OS Vista+ using WMI or Shell objects (I have never needed it!). BR, UEZ UEZ not sure if your still looking at this but I did find out an easy way to do this in Vista+ check my modified code, uses a different WMI Class but its pretty simple. #RequireAdmin Global $ip = "localhost" If $CmdLine[0] > 0 Then $ip = $CmdLine[1] $AdaptDescription = "'Cisco Anyconnect VPN Virtual Miniport Adapter for Windows'" $objWMIService = ObjGet("winmgmts:{impersonationLevel = impersonate}!\\" & $ip & "\root\cimv2") GetWMI($ip) Func GetWMI($srv) Local $colItems If $objWMIService.ExecQuery("SELECT Description FROM Win32_NetworkAdapter WHERE NetEnabled = True AND Description = " & $AdaptDescription).Count > 0 Then $colItems = $objWMIService.ExecQuery("SELECT Description FROM Win32_NetworkAdapter WHERE NetEnabled = True AND Description = " & $AdaptDescription) If IsObj($colItems) Then For $objItem In $colItems $objItem.Disable() Next EndIf EndIf EndFunc
UEZ Posted October 14, 2010 Posted October 14, 2010 joe1981al, thanks for the hint how to disable the network adapter using WMI! When I found the time I will test it! Br, 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!¯\_(ツ)_/¯ ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ
joe1981al Posted October 14, 2010 Posted October 14, 2010 joe1981al, thanks for the hint how to disable the network adapter using WMI! When I found the time I will test it! Br, UEZ I'm using on Win7 perfectly, I wrote this to be cross platform, I call the AdapterKill function with variables from an INI file so a compiled file can be distributed and then customized with ini for the variables. It seems that all the stuff I want to do with autoit is out on the fringes and I have to come up with ways to make it happen... expandcollapse popup#RequireAdmin Func AdapterKill($AdaptDescription, $ConnectionName, $bEnable = false) ;$AdaptDescription = "' '" ;for Vista/Win7 Actual Adapter Name must be single quoted inside double-quotes ;$ConnectionName = " " ;for PreVista Connection Name in Net Connections if @OSType<>"WIN32_NT" then SetError(1) endif if @OSVersion="WIN_2000" then $strFolderName = "Network and Dial-up Connections" PreVistaDisable($ConnectionName,$strFolderName,$bEnable) Return 0 elseif StringInStr(@OSVersion, "WIN_XP") then $strFolderName = "Network Connections" PreVistaDisable($ConnectionName,$strFolderName,$bEnable) Return 0 else VistaDisable($AdaptDescription,$bEnable) Return 0 endif EndFunc Func VistaDisable($Adapter, $bEnable = false) $objWMIService = ObjGet("winmgmts:{impersonationLevel = impersonate}!\\" & "." & "\root\cimv2") If $objWMIService.ExecQuery("SELECT Description FROM Win32_NetworkAdapter WHERE NetEnabled = True AND Description = " & $Adapter).Count > 0 Then $colItems = $objWMIService.ExecQuery("SELECT Description FROM Win32_NetworkAdapter WHERE NetEnabled = True AND Description = " & $Adapter) If IsObj($colItems) Then For $objItem In $colItems If $bEnable = False Then $objItem.Disable() Else $objItem.Enable() EndIf Next Return 0 EndIf EndIf EndFunc Func PreVistaDisable($oLanConnection,$strFolderName, $bEnable = false) ;$bEnable = false ; Change this to 'false' to DISABLE the network adapter Select Case StringInStr("0409,0809,0c09,1009,1409,1809,1c09,2009, 2409,2809,2c09,3009,3409", @OSLang) ; English (United States) $strEnableVerb = "En&able" $strDisableVerb = "Disa&ble" ; Add here the correct Verbs for your Operating System Language EndSelect ;Virtual folder containing icons for the Control Panel applications. (value = 3) Const $ssfCONTROLS = 3 $ShellApp = ObjCreate("Shell.Application") $oControlPanel = $shellApp.Namespace($ssfCONTROLS) ; Find 'Network connections' control panel item $oNetConnections="" For $FolderItem in $oControlPanel.Items If $FolderItem.Name = $strFolderName then $oNetConnections = $FolderItem.GetFolder Exitloop Endif Next If not IsObj($oNetConnections) Then SetError(1) EndIf For $FolderItem In $oNetConnections.Items If StringLower($FolderItem.Name) = StringLower($oLanConnection) Then $oLanConnection = $FolderItem Exitloop EndIf Next If not IsObj($oLanConnection) Then SetError(1) EndIf $oEnableVerb="" $oDisableVerb="" For $Verb In $oLanConnection.Verbs If $Verb.Name = $strEnableVerb Then $oEnableVerb = $Verb EndIf If $Verb.Name = $strDisableVerb Then $oDisableVerb = $Verb EndIf Next If $bEnable then If IsObj($oEnableVerb) Then $oEnableVerb.DoIt ; Enable network card Endif If not $bEnable then If IsObj($oDisableVerb) Then $oDisableVerb.DoIt; Disable network card EndIf Sleep(1000) EndFunc
iXX Posted October 20, 2010 Posted October 20, 2010 OK, how to modify this script to disable "Hamachi" (Description:"Hamachi Network Interface"), if my system language is CZECH? (winXP)
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