Jade Posted March 31, 2006 Posted March 31, 2006 Hi, This is probably something simple that's been done before, but I can't find it in the forum, and I'm new to AutoIt... I'm trying to write something that'll disable or enable an interface in the Network Connections window. I got Network Connections to pop up by using Run("rundll32.exe shell32.dll, Control_RunDLL ncpa.cpl"). But once I get there, the AutoIt Window Info doesn't show any control ID for "Local Area Connection", so that means I can't use ControlClick to select that interface, right? So how do I do it? I could use Send("L"), but then what if there are multiple "Local Area Connection *" interfaces? How would I know that I picked the right one (besides verifying the window that pops up after clicking on one of them)?
Bert Posted March 31, 2006 Posted March 31, 2006 (edited) I found this: CODE; 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 = true ; Change this to 'false' to DISABLE the network adapterif @OSType<>"WIN32_NT" then Msgbox(0,"","This script requires Windows 2000 or higher.") exitendifif @OSVersion="WIN_2000" then $strFolderName = "Network and Dial-up Connections"else $strFolderName = "Network Connections"; Windows XPendifSelect 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 LanguageEndSelect;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 EndifNext If not IsObj($oNetConnections) Then MsgBox(0,"Error","Couldn't find " & $strFolderName & " folder." ExitEndIf For $FolderItem In $oNetConnections.Items If StringLower($FolderItem.Name) = StringLower($oLanConnection) Then $oLanConnection = $FolderItem Exitloop EndIfNextIf not IsObj($oLanConnection) Then MsgBox(0,"Error","Couldn't find " & $oLanConnection & " Item." ExitEndIf$oEnableVerb=""$oDisableVerb=""For $Verb In $oLanConnection.VerbsIf $Verb.Name = $strEnableVerb Then $oEnableVerb = $VerbEndIfIf $Verb.Name = $strDisableVerb Then $oDisableVerb = $VerbEndIfNextIf $bEnable thenIf IsObj($oEnableVerb) Then $oEnableVerb.DoIt ; Enable network cardEndifIf not $bEnable thenIf IsObj($oDisableVerb) Then $oDisableVerb.DoIt; Disable network cardEndIfSleep(1000)I hope this will solve your problem. I found it here:http://www.autoitscript.com/forum/index.php?showtopic=12645 Edited March 31, 2006 by vollyman The Vollatran project My blog: http://www.vollysinterestingshit.com/
blindwig Posted March 31, 2006 Posted March 31, 2006 I wrote a script to enable and disable network interfaces using a command line tool called DevCon. It's feely available. It's cryptic and hard to use at first if you're not familiar with the Windows hardware scheme, but it works well. My UDF Threads:Pseudo-Hash: Binary Trees, Flat TablesFiles: Filter by Attribute, Tree List, Recursive Find, Recursive Folders Size, exported to XMLArrays: Nested, Pull Common Elements, Display 2dSystem: Expand Environment Strings, List Drives, List USB DrivesMisc: Multi-Layer Progress Bars, Binary FlagsStrings: Find Char(s) in String, Find String in SetOther UDF Threads I Participated:Base64 Conversions
Jade Posted March 31, 2006 Author Posted March 31, 2006 Thanks blindwig, volleyman, I want to avoid adding DevCon if possible. I've got too many testing tools to deal with right now as it is. I will try the code volleyman provided and let you know how it goes. One question about the code though: Does the Control Panel need to be activated before we call this function or does it take care of enabling/disabling the interface even if Control Panel is not activated? Thanks again.
Jade Posted April 1, 2006 Author Posted April 1, 2006 Ok, to answer my own question, no, Control Panel did not need to be activated beforehand. I guess that's the point of using the COM. I finally got it to work for me after fixing a few syntax errors and tweaking it a bit so that I could pass the interface name and the enable/disable option via the command line. I learned a lot while deceiphering this...thanks for sharing it!
herewasplato Posted April 1, 2006 Posted April 1, 2006 Ok, to answer my own question, no, Control Panel did not need to be activated beforehand. I guess that's the point of using the COM. I finally got it to work for me after fixing a few syntax errors and tweaking it a bit so that I could pass the interface name and the enable/disable option via the command line. I learned a lot while deceiphering this...thanks for sharing it!I know that you said that you got it working - but take a look at this:http://www.autoitscript.com/forum/index.ph...showtopic=21229 [size="1"][font="Arial"].[u].[/u][/font][/size]
Jade Posted April 3, 2006 Author Posted April 3, 2006 I know that you said that you got it working - but take a look at this:http://www.autoitscript.com/forum/index.ph...showtopic=21229Cool, thanks!
Neoborn Posted April 3, 2006 Posted April 3, 2006 If you are new to AutoIT and would like to get the basics down quicker, check out this awesome new coaching tool...And if you find it useful ...vote http://www.autoitscript.com/forum/index.php?showtopic=24117 ~Projects~1. iPod Ejector 1.0 - Tool Used To Eject iPod in Windows - Uses DevEject.exe :P2. SmartFTP Close Popup Tool - Closes reminders from freeware SmartFTP.~Helpful Links For New Users~1. LXP's Learning AutoIT PDF Guide - <<< Go here for a PDF Guide on learning AutoIT from the ground up!<<<2. AutoIt 1-2-3 <<<Want to learn more about AutoIT quickly? Go Here<<<3. How To Install The Beta And Production Versions Of AutoIT / SciteAutoIT
Jade Posted April 4, 2006 Author Posted April 4, 2006 If you are new to AutoIT and would like to get the basics down quicker, check out this awesome new coaching tool...And if you find it useful ...vote http://www.autoitscript.com/forum/index.php?showtopic=24117Wish I'd seen this a few months ago. Thanks.
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