Network LAN Connection to be Enabled/Disabled

Reply

Join Date: Jul 2006
Posts: 45
Reputation: maheshsayani is an unknown quantity at this point 
Solved Threads: 2
maheshsayani's Avatar
maheshsayani maheshsayani is offline Offline
Light Poster

Network LAN Connection to be Enabled/Disabled

 
0
  #1
Jul 17th, 2006
Hi To All,

How can the Network LAN Connection to be Enabled/Disabled
through Vb Code
Reply With Quote Quick reply to this message  
Join Date: Dec 2004
Posts: 2,413
Reputation: Comatose is a jewel in the rough Comatose is a jewel in the rough Comatose is a jewel in the rough Comatose is a jewel in the rough 
Solved Threads: 211
Team Colleague
Comatose's Avatar
Comatose Comatose is offline Offline
Taboo Programmer

Re: Network LAN Connection to be Enabled/Disabled

 
0
  #2
Jul 17th, 2006
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)
  1. Dim objCP, objEnable, objDisable, colNetwork
  2. Dim clsConn, clsLANConn, clsVerb
  3. Dim strNetConn, strConn, strEnable, strDisable
  4. Dim bEnabled, bDisabled
  5.  
  6. strNetConn = "Network Connections"
  7. strConn = "Local Area Connection"
  8.  
  9. strEnable = "En&able"
  10. strDisable = "Disa&ble"
  11.  
  12. Set objshell = CreateObject("Shell.Application")
  13.  
  14. If objshell Is Nothing Then
  15. MsgBox "Fooey"
  16. Exit Sub
  17. End If
  18.  
  19.  
  20. Set objCP = objshell.NameSpace(3) 'Control Panel
  21.  
  22. Set colNetwork = Nothing
  23. For Each clsConn In objCP.Items
  24. If clsConn.Name = strNetConn Then
  25. Set colNetwork = clsConn.GetFolder
  26. Exit For
  27. End If
  28. Next
  29.  
  30. If colNetwork Is Nothing Then
  31. MsgBox "Network folder not found"
  32. Exit Sub
  33. End If
  34.  
  35. Set clsLANConn = Nothing
  36. For Each clsConn In colNetwork.Items
  37. If InStr(LCase(clsConn.Name), LCase(strConn)) Then
  38. Set clsLANConn = clsConn
  39. Exit For
  40. End If
  41. Next
  42.  
  43. If clsLANConn Is Nothing Then
  44. MsgBox "Network Connection not found"
  45. Exit Sub
  46. End If
  47.  
  48. bEnabled = True
  49. Set objEnable = Nothing
  50. Set objDisable = Nothing
  51.  
  52. For Each clsVerb In clsLANConn.Verbs
  53. If clsVerb.Name = strEnable Then
  54. Set objEnable = clsVerb
  55. bEnabled = False
  56. End If
  57. If clsVerb.Name = strDisable Then
  58. Set objDisable = clsVerb
  59. End If
  60. Next
  61.  
  62. If bEnabled Then
  63. objDisable.DoIt
  64. Else
  65. objEnable.DoIt
  66. End If
Last edited by Comatose; Jul 17th, 2006 at 8:09 am. Reason: Code Credit Belongs To: Chris Brooke at MCP Mag
Reply With Quote Quick reply to this message  
Join Date: Jul 2006
Posts: 45
Reputation: maheshsayani is an unknown quantity at this point 
Solved Threads: 2
maheshsayani's Avatar
maheshsayani maheshsayani is offline Offline
Light Poster

Re: Network LAN Connection to be Enabled/Disabled

 
0
  #3
Jul 17th, 2006
Thanks For your help Mr.Comatose.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the Visual Basic 4 / 5 / 6 Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC