Jump to content

This site uses cookies. By continuing to browse the site you are agreeing to our use of cookies. Find out more here. X
X


Photo

QuickNIC


  • Please log in to reply
8 replies to this topic

#1 spudw2k

spudw2k

    passionately misinformed

  • Active Members
  • PipPipPipPipPipPip
  • 1,283 posts

Posted 07 September 2007 - 10:27 PM

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.


AutoIt         
#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 by spudw2k, 22 December 2007 - 07:44 AM.








#2 krigaren

krigaren

    Seeker

  • Active Members
  • 6 posts

Posted 09 September 2007 - 06:45 AM

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 by krigaren, 09 September 2007 - 06:46 AM.


#3 spudw2k

spudw2k

    passionately misinformed

  • Active Members
  • PipPipPipPipPipPip
  • 1,283 posts

Posted 17 September 2007 - 07:46 PM

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.0
Fixed trayicon

edit:
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.

Attached Files


Edited by spudw2k, 10 November 2011 - 04:59 PM.


#4 ptrex

ptrex

    Universalist

  • MVPs
  • 2,419 posts

Posted 19 September 2007 - 10:45 AM

@spudw2k

Nice application !!

But your latest version is bringing up lots of errors of non decl. vars.

Regards

ptrex

#5 krigaren

krigaren

    Seeker

  • Active Members
  • 6 posts

Posted 19 September 2007 - 01:32 PM

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..

#6 spudw2k

spudw2k

    passionately misinformed

  • Active Members
  • PipPipPipPipPipPip
  • 1,283 posts

Posted 19 September 2007 - 04:27 PM

@spudw2k

Nice application !!

But your latest version is bringing up lots of errors of non decl. vars.

Regards

ptrex



What version of AutoItv3 are you using? It works fine for me using v3.2.4.9

If you give me the error and line# I'd take alook.

#7 spudw2k

spudw2k

    passionately misinformed

  • Active Members
  • PipPipPipPipPipPip
  • 1,283 posts

Posted 21 December 2007 - 05:21 PM

Just verified. Code is working with version 3.2.10.0.

Edited by spudw2k, 22 December 2007 - 07:42 AM.


#8 martin

martin

    ~~\o/~~~/0\=¬''~~~

  • MVPs
  • 7,321 posts

Posted 21 December 2007 - 05:47 PM

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.

#9 sulfurious

sulfurious

    Universalist

  • Active Members
  • PipPipPipPipPip
  • 261 posts

Posted 21 December 2007 - 06:05 PM

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.

Plain Text         
'~ 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





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users