944,033 Members | Top Members by Rank

Ad:
Jul 17th, 2006
0

Network LAN Connection to be Enabled/Disabled

Expand Post »
Hi To All,

How can the Network LAN Connection to be Enabled/Disabled
through Vb Code
Similar Threads
Reputation Points: 10
Solved Threads: 2
Light Poster
maheshsayani is offline Offline
45 posts
since Jul 2006
Jul 17th, 2006
0

Re: 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)
  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
Team Colleague
Reputation Points: 361
Solved Threads: 214
Taboo Programmer
Comatose is offline Offline
2,413 posts
since Dec 2004
Jul 17th, 2006
0

Re: Network LAN Connection to be Enabled/Disabled

Thanks For your help Mr.Comatose.
Reputation Points: 10
Solved Threads: 2
Light Poster
maheshsayani is offline Offline
45 posts
since Jul 2006
Feb 3rd, 2011
-1
Re: Network LAN Connection to be Enabled/Disabled
how can know the lan cable has been connected or not in vb6
Reputation Points: 10
Solved Threads: 0
Newbie Poster
rrajmca is offline Offline
1 posts
since Feb 2011
Feb 3rd, 2011
0
Re: Network LAN Connection to be Enabled/Disabled
@rrajm, you need to open your OWN thread, we will then answer from there. This is a VERY old post(2006), nobody will give you help from here. Click HERE to open a new thread.
Reputation Points: 329
Solved Threads: 347
Senior Poster
AndreRet is offline Offline
3,700 posts
since Jan 2008

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Visual Basic 4 / 5 / 6 Forum Timeline: Getting data from database to checkboxes
Next Thread in Visual Basic 4 / 5 / 6 Forum Timeline: restaurant billing softwrae in vb6





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC