spudw2k Posted September 7, 2007 Share Posted September 7, 2007 (edited) A co-worker of mine was working remotely yesterday and asked if I knew of a way to easy and quickly enable/disable his wireless card rather than the tediousness of opening Network Connections, right-click and (En/Dis)able. I found a vbscript that uses a Shell object to do essentially the same thing, but I took the liberty of improving it. I converted the script to AutoIt to increase functionality and add a gui. I designed it to run the in systemtray for ease. Take a look and hopefully someone else will find it useful.---update---Code has been updated. Download version 2 below on my second post. The original code is left available for reference.expandcollapse popup#include <Array.au3> Opt("TrayMenuMode",1) TraySetIcon("Shell32.dll",-150) TraySetToolTip("QuickNIC") Func GetNetworkConnections() $objWMIService = ObjGet("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2") If not IsObj($objWMIService) Then return 0 $colItems = $objWMIService.ExecQuery("SELECT NetConnectionID FROM Win32_NetworkAdapter") $strData = "" For $objItem in $colItems If $objItem.NetConnectionID <> "" Then $strData = $strData & $objItem.NetConnectionID & "|" Next If StringLen($strData) > 2 Then $strData = StringLeft($strData,StringLen($strData)-1) Else msgbox(0,"","No Networks Found.") return 0 EndIf Return $strData EndFunc Func ToggleNetworkInterface($strConn) $objShell = ObjCreate("Shell.Application") $strNetConn = "Network Connections" $strEnable = "En&able" $strDisable = "Disa&ble" $objCP = $objShell.Namespace(3) $colNetwork = "" For $clsConn In $objCP.Items If $clsConn.Name = $strNetConn Then $colNetwork = $clsConn.GetFolder Next If $colNetwork = "" Then msgbox(0,"","Failed to Find Network Connections") Exit EndIf $clsLANConn = "" For $clsConn In $colNetwork.Items If StringLower($clsConn.Name) = StringLower($strConn) Then $clsLANConn = $clsConn Next If $clsLANConn = "" Then Msgbox(0,"","Cannot find Network by the name of: " & $strConn) Exit EndIf For $clsVerb in $clsLANConn.verbs If $clsVerb.name = $strDisable Then $clsVerb.DoIt sleep(100) Return 0 EndIf If $clsVerb.name = $strEnable Then $clsVerb.DoIt sleep(100) Return 1 EndIf Next EndFunc Func LoadInterface() $arrData = StringSplit(GetNetworkConnections(),"|") _ArrayDelete($arrData,0) _ArraySort($arrData) Dim $NetConn[1] For $i = 0 to UBound($arrData) - 1 $NetConn[$i] = TrayCreateItem($arrData[$i]) ReDim $NetConn[$i + 2] Next $separator = TrayCreateItem("") $trayabout = TrayCreateItem("About") $trayexit = TrayCreateItem("Exit") While 1 $msg = TrayGetMsg() If $msg > 0 and $msg <> $trayabout and $msg <> $trayexit Then ToggleNetworkInterface(TrayItemGetText($msg)) EndIf If $msg = $trayabout Then SplashTextOn("About...","QuickNIC is a tool that provides a quick and easy method to toggle (enable/disable) your Network Connections." & @CRLF & @CRLF & "version 0.1b",300,120) sleep(3500) SplashOff() EndIf If $msg = $trayexit Then ExitLoop WEnd EndFunc LoadInterface() Edited December 22, 2007 by spudw2k Spoiler Things I've Made: Always On Top Tool ◊ AU History ◊ Deck of Cards ◊ HideIt ◊ ICU ◊ Icon Freezer ◊ Ipod Ejector ◊ Junos Configuration Explorer ◊ Link Downloader ◊ MD5 Folder Enumerator ◊ PassGen ◊ Ping Tool ◊ Quick NIC ◊ Read OCR ◊ RemoteIT ◊ SchTasksGui ◊ SpyCam ◊ System Scan Report Tool ◊ System UpTime ◊ Transparency Machine ◊ VMWare ESX Builder Misc Code Snippets: ADODB Example ◊ CheckHover ◊ Detect SafeMode ◊ DynEnumArray ◊ GetNetStatData ◊ HashArray ◊ IsBetweenDates ◊ Local Admins ◊ Make Choice ◊ Recursive File List ◊ Remove Sizebox Style ◊ Retrieve PNPDeviceID ◊ Retrieve SysListView32 Contents ◊ Set IE Homepage ◊ Tickle Expired Password ◊ Transpose Array Projects: Drive Space Usage GUI ◊ LEDkIT ◊ Plasma_kIt ◊ Scan Engine Builder ◊ SpeeDBurner ◊ SubnetCalc Cool Stuff: AutoItObject UDF ◊ Extract Icon From Proc ◊ GuiCtrlFontRotate ◊ Hex Edit Funcs ◊ Run binary ◊ Service_UDF Link to comment Share on other sites More sharing options...
krigaren Posted September 9, 2007 Share Posted September 9, 2007 (edited) The script is great and very useful. Is it possible to add the current status to each nic, it´s so easy to disable the wrong nic when they don´t show the status. anyway. great job, keep it up. Edited September 9, 2007 by krigaren Link to comment Share on other sites More sharing options...
spudw2k Posted September 17, 2007 Author Share Posted September 17, 2007 (edited) I should be able to do that fairly easily with checkboxes, but I'm just trying to find the best way to minimize my code. I'll post the updated version when it's working best.---update---Ok, here is the updated version with status of each NIC. Enjoy.---update---Found a bug. Remove Wizards. Fixed and reposted v2.---update---Checked code against version 3.2.10.0Fixed trayiconedit:WARNING! this script does not work with Windows 7 (at least not 64-bit but I doubt x86 works either).I may update it eventually.QuickNICV2.au3 Edited November 10, 2011 by spudw2k Spoiler Things I've Made: Always On Top Tool ◊ AU History ◊ Deck of Cards ◊ HideIt ◊ ICU ◊ Icon Freezer ◊ Ipod Ejector ◊ Junos Configuration Explorer ◊ Link Downloader ◊ MD5 Folder Enumerator ◊ PassGen ◊ Ping Tool ◊ Quick NIC ◊ Read OCR ◊ RemoteIT ◊ SchTasksGui ◊ SpyCam ◊ System Scan Report Tool ◊ System UpTime ◊ Transparency Machine ◊ VMWare ESX Builder Misc Code Snippets: ADODB Example ◊ CheckHover ◊ Detect SafeMode ◊ DynEnumArray ◊ GetNetStatData ◊ HashArray ◊ IsBetweenDates ◊ Local Admins ◊ Make Choice ◊ Recursive File List ◊ Remove Sizebox Style ◊ Retrieve PNPDeviceID ◊ Retrieve SysListView32 Contents ◊ Set IE Homepage ◊ Tickle Expired Password ◊ Transpose Array Projects: Drive Space Usage GUI ◊ LEDkIT ◊ Plasma_kIt ◊ Scan Engine Builder ◊ SpeeDBurner ◊ SubnetCalc Cool Stuff: AutoItObject UDF ◊ Extract Icon From Proc ◊ GuiCtrlFontRotate ◊ Hex Edit Funcs ◊ Run binary ◊ Service_UDF Link to comment Share on other sites More sharing options...
ptrex Posted September 19, 2007 Share Posted September 19, 2007 @spudw2k Nice application !! But your latest version is bringing up lots of errors of non decl. vars. Regards ptrex Contributions :Firewall Log Analyzer for XP - Creating COM objects without a need of DLL's - UPnP support in AU3Crystal Reports Viewer - PDFCreator in AutoIT - Duplicate File FinderSQLite3 Database functionality - USB Monitoring - Reading Excel using SQLRun Au3 as a Windows Service - File Monitor - Embedded Flash PlayerDynamic Functions - Control Panel Applets - Digital Signing Code - Excel Grid In AutoIT - Constants for Special Folders in WindowsRead data from Any Windows Edit Control - SOAP and Web Services in AutoIT - Barcode Printing Using PS - AU3 on LightTD WebserverMS LogParser SQL Engine in AutoIT - ImageMagick Image Processing - Converter @ Dec - Hex - Bin -Email Address Encoder - MSI Editor - SNMP - MIB ProtocolFinancial Functions UDF - Set ACL Permissions - Syntax HighLighter for AU3ADOR.RecordSet approach - Real OCR - HTTP Disk - PDF Reader Personal Worldclock - MS Indexing Engine - Printing ControlsGuiListView - Navigation (break the 4000 Limit barrier) - Registration Free COM DLL Distribution - Update - WinRM SMART Analysis - COM Object Browser - Excel PivotTable Object - VLC Media Player - Windows LogOnOff Gui -Extract Data from Outlook to Word & Excel - Analyze Event ID 4226 - DotNet Compiler Wrapper - Powershell_COM - New Link to comment Share on other sites More sharing options...
krigaren Posted September 19, 2007 Share Posted September 19, 2007 This is even better then i expected. you have done a beautiful job. Thanks for sharing.. I think this script is every networkadmins second best friend. Thanks again.. Link to comment Share on other sites More sharing options...
spudw2k Posted September 19, 2007 Author Share Posted September 19, 2007 @spudw2kNice application !!But your latest version is bringing up lots of errors of non decl. vars.RegardsptrexWhat version of AutoItv3 are you using? It works fine for me using v3.2.4.9If you give me the error and line# I'd take alook. Spoiler Things I've Made: Always On Top Tool ◊ AU History ◊ Deck of Cards ◊ HideIt ◊ ICU ◊ Icon Freezer ◊ Ipod Ejector ◊ Junos Configuration Explorer ◊ Link Downloader ◊ MD5 Folder Enumerator ◊ PassGen ◊ Ping Tool ◊ Quick NIC ◊ Read OCR ◊ RemoteIT ◊ SchTasksGui ◊ SpyCam ◊ System Scan Report Tool ◊ System UpTime ◊ Transparency Machine ◊ VMWare ESX Builder Misc Code Snippets: ADODB Example ◊ CheckHover ◊ Detect SafeMode ◊ DynEnumArray ◊ GetNetStatData ◊ HashArray ◊ IsBetweenDates ◊ Local Admins ◊ Make Choice ◊ Recursive File List ◊ Remove Sizebox Style ◊ Retrieve PNPDeviceID ◊ Retrieve SysListView32 Contents ◊ Set IE Homepage ◊ Tickle Expired Password ◊ Transpose Array Projects: Drive Space Usage GUI ◊ LEDkIT ◊ Plasma_kIt ◊ Scan Engine Builder ◊ SpeeDBurner ◊ SubnetCalc Cool Stuff: AutoItObject UDF ◊ Extract Icon From Proc ◊ GuiCtrlFontRotate ◊ Hex Edit Funcs ◊ Run binary ◊ Service_UDF Link to comment Share on other sites More sharing options...
spudw2k Posted December 21, 2007 Author Share Posted December 21, 2007 (edited) Just verified. Code is working with version 3.2.10.0. Edited December 22, 2007 by spudw2k Spoiler Things I've Made: Always On Top Tool ◊ AU History ◊ Deck of Cards ◊ HideIt ◊ ICU ◊ Icon Freezer ◊ Ipod Ejector ◊ Junos Configuration Explorer ◊ Link Downloader ◊ MD5 Folder Enumerator ◊ PassGen ◊ Ping Tool ◊ Quick NIC ◊ Read OCR ◊ RemoteIT ◊ SchTasksGui ◊ SpyCam ◊ System Scan Report Tool ◊ System UpTime ◊ Transparency Machine ◊ VMWare ESX Builder Misc Code Snippets: ADODB Example ◊ CheckHover ◊ Detect SafeMode ◊ DynEnumArray ◊ GetNetStatData ◊ HashArray ◊ IsBetweenDates ◊ Local Admins ◊ Make Choice ◊ Recursive File List ◊ Remove Sizebox Style ◊ Retrieve PNPDeviceID ◊ Retrieve SysListView32 Contents ◊ Set IE Homepage ◊ Tickle Expired Password ◊ Transpose Array Projects: Drive Space Usage GUI ◊ LEDkIT ◊ Plasma_kIt ◊ Scan Engine Builder ◊ SpeeDBurner ◊ SubnetCalc Cool Stuff: AutoItObject UDF ◊ Extract Icon From Proc ◊ GuiCtrlFontRotate ◊ Hex Edit Funcs ◊ Run binary ◊ Service_UDF Link to comment Share on other sites More sharing options...
martin Posted December 21, 2007 Share Posted December 21, 2007 Just verified. Code is working with version 3.2.10.0. Compiled Code uploaded.It does indeed. Very useful - thanks spudw2k. Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script. Link to comment Share on other sites More sharing options...
sulfurious Posted December 21, 2007 Share Posted December 21, 2007 Nice. Here is what I have been using for a while. VBS, but same difference. This is for XP, I have a different one for 2k, small differences. Sul. expandcollapse popup'~ Toggle a SPECIFIED NIC on or off Option Explicit Dim objShell Dim objCP, objEnable, objDisable, colNetwork Dim clsConn, clsLANConn, clsVerb Dim strNetConn, strConn, strEnable, strDisable Dim bEnabled, bDisabled strNetConn = "Network Connections" strConn = "name of your network adapter here" strEnable = "En&able" strDisable = "Disa&ble" Set objShell = CreateObject("Shell.Application") Set objCP = objShell.Namespace(3) 'Control Panel Set colNetwork = Nothing For Each clsConn in objCP.Items If clsConn.Name = strNetConn Then Set colNetwork = clsConn.getfolder Exit For End If Next If colNetwork is Nothing Then WScript.Echo "Network folder not found" WScript.Quit End If Set clsLANConn = Nothing For Each clsConn in colNetwork.Items '~ ‘In case the LAN is named "connection 2", etc. If Instr(LCase(clsConn.name),LCase(strConn)) Then Set clsLANConn = clsConn Exit For End If Next If clsLANConn is Nothing Then WScript.Echo "Network Connection not found" WScript.Quit End If bEnabled = True Set objEnable = Nothing Set objDisable = Nothing For Each clsVerb in clsLANConn.verbs If clsVerb.name = strEnable Then Set objEnable = clsVerb bEnabled = False End If If clsVerb.name = strDisable Then Set objDisable = clsVerb End If Next If bEnabled Then objDisable.DoIt Else objEnable.DoIt End If '~ Give the connection time to stop/start WScript.Sleep 1000 WScript.Quit 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