Hello, I am attempting to write a program that will disable the Local Area Connection while leaving the Wireless connection enabled. My company is using net-books in our stores to demo air-cards and we need to keep them off of the LAN. I'm new to VB and VB.net, and it's been a while since I did any type of programming. I've gathered some code that others have posted in forums and tutorials and I'm working through a tutorial book, but I finally believe that I am stuck.
I have a form that contains a user name and password field and a log on button as well as an exit button. Once the user name and password are input and the log on button in pushed, it should call up the 'ToggleNetworkConnection.vb' class and execute the code that is in there. Any help would be much appreciated! Once again, I'm fairly new to this, so if you see any ways to make this more efficient, please feel free to offer criticism!
Here is the code for the Form1
Public Class Form1 Inherits System.Windows.Forms.Form Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim Username As String Dim Password As String Dim DisablePort As ToggleNetworkConnection() Username = "admin" 'username box Password = "admin" 'password box If TextBox1.Text = Username And TextBox2.Text = Password Then 'make sure they authenticate 'this is where I believe the code to call the TogglenetworkConnection.vb should go End If End Sub Private Sub TextBox2_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox2.TextChanged TextBox2.PasswordChar = "*" 'makes the password show up as * instead of letters End Sub Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click 'insert code to exit the program End Sub Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load End Sub Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged End Sub End Class
Here is the code for the ToggleNetworkConnection.vb class
Public Class ToggleNetworkConnection #Region "Public Methods" Public Shared Sub ToggleLocalAreaConnection() For Each verb As Shell32.FolderItemVerb In LocalAreaConnectionFolderItem.Verbs If verb.Name = "Disa&ble" Then verb.DoIt() Exit For End If Next Threading.Thread.Sleep(1000) End Sub #End Region #Region "Properties" Private Shared ReadOnly Property ControlPanelFolder() Get Dim shell As New Shell32.Shell() Return shell.NameSpace(3) End Get End Property Private Shared ReadOnly Property NetworkFolder() As Shell32.Folder Get Dim retVal As Shell32.Folder = Nothing For Each fi As Shell32.FolderItem In ControlPanelFolder.Items If fi.Name = "Network Connections" Then retVal = fi.GetFolder() End If Next If retVal Is Nothing Then Throw New NetworkConnectionsFolderNotFoundException() Else Return retVal End If End Get End Property Private Shared ReadOnly Property LocalAreaConnectionFolderItem() As Shell32.FolderItem Get Dim retVal As Shell32.FolderItem = Nothing For Each folderItem As Shell32.FolderItem In NetworkFolder.Items Console.WriteLine(folderItem.Name) If InStr(folderItem.Name.ToLower(), "Local Area Connection".ToLower()) Then retVal = folderItem Exit For End If Next If retVal Is Nothing Then Throw New LocalAreaConnectionFolderItemNotFoundException() Else Return retVal End If End Get End Property #End Region #Region "Custom Exceptions" Public Class NetworkConnectionsFolderNotFoundException Inherits Exception Public Overrides ReadOnly Property Message() As String Get Return "The Network Connections Folder Could Not Be Found!" End Get End Property End Class Public Class LocalAreaConnectionFolderItemNotFoundException Inherits Exception Public Overrides ReadOnly Property Message() As String Get Return "The Local Area Connection Folder Could Not Be Found!" End Get End Property End Class #End Region End Class
Here is the code for the Module1 which I believe calls Form1
Module Module1 Dim MainMenu As New Form1() Sub Main() MainMenu.Show() End Sub End Module
Once again, any help would be great!