| | |
Network LAN Connection to be Enabled/Disabled
![]() |
This code actually "toggles" the connection, by retrieving it's current state, and then setting the opposite state..... but, in vb6 you'll need to add a reference to "Microsoft Shell Controls and Automation" before it will work for you, plus, you may need to change some variables to fit the name of your connection....
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
Dim objCP, objEnable, objDisable, colNetwork Dim clsConn, clsLANConn, clsVerb Dim strNetConn, strConn, strEnable, strDisable Dim bEnabled, bDisabled strNetConn = "Network Connections" strConn = "Local Area Connection" strEnable = "En&able" strDisable = "Disa&ble" Set objshell = CreateObject("Shell.Application") If objshell Is Nothing Then MsgBox "Fooey" Exit Sub End If 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 MsgBox "Network folder not found" Exit Sub End If Set clsLANConn = Nothing For Each clsConn In colNetwork.Items If InStr(LCase(clsConn.Name), LCase(strConn)) Then Set clsLANConn = clsConn Exit For End If Next If clsLANConn Is Nothing Then MsgBox "Network Connection not found" Exit Sub 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
Last edited by Comatose; Jul 17th, 2006 at 8:09 am. Reason: Code Credit Belongs To: Chris Brooke at MCP Mag
![]() |
Similar Threads
- Added an Ethernet Adapter Card (NIC), but no LAN! (PCI and Add-In Cards)
- Can't connect to the internet (IT Professionals' Lounge)
- cable problems (Networking Hardware Configuration)
- A7N8X-X MCP LAN Connection Problem (Windows NT / 2000 / XP)
- Enabling disable/enable property for LAN connection in limited a/c (Windows NT / 2000 / XP)
- How to Enable ICS on a Home or Small Office Network Connection in Windows XP (Windows tips 'n' tweaks)
Other Threads in the Visual Basic 4 / 5 / 6 Forum
- Previous Thread: Pass variables through network connection
- Next Thread: Listbox Help
| Thread Tools | Search this Thread |
* 6 2007 access activex add age basic beginner birth bmp calculator cd cells.find click client code college connection connectionproblemusingvb6usingoledb creat ctrl+f data database datareport date delete dissertations dissertationthesis dissertationtopic edit excel excelmacro file filename form header iamthwee image inboxinvb internetfiledownload listbox listview liveperson login looping microsoft movingranges number objectinsert open oracle password prime program prompt range-objects readfile reading remotesqlserverdatabase report save search sendbyte sites sql sql2008 sqlserver subroutine tags time urldownloadtofile vb vb6 vb6.0 vba visual visualbasic visualbasic6 web windows






