How to connect computer using hotspot by create programme in VB .Net

I am going to explain how to create windows utility for create hotspot and connect it with other machine

Step :
1. Take 2 text box one for user id (i.e txtUserName) and one for password (i.e txtPassword)
2. Take 1 button using that we can execute the command to create hotspot using entered credential.
3. call following sample code to create hotspot on click of button.

// Sample Code

    Public s As String
    Public i As Integer
    Public flag As Boolean = True
    
    If (flag = True) Then
            flag = False
            Button1.Text = "Stop"
            txtUserName.Enabled = False
            txtPassword.Enabled = False
            i = txtPassword.TextLength
            If (i < 6) Then
                MessageBox.Show("Password must be >= 6 character", "Password")
            Else
                s = "netsh wlan show drivers" + vbNewLine + "netsh wlan set hostednetwork mode=allow ssid=" + txtUserName.Text + " " + "key=" + 
               txtPassword.Text + vbNewLine + "netsh wlan start hostednetwork"
                RichTextBox1.Text = s
                RichTextBox1.SaveFile(Application.StartupPath + "\wifi.bat", RichTextBoxStreamType.PlainText)
                Try
                    Dim procInfo As New ProcessStartInfo()
                    procInfo.UseShellExecute = True
                    procInfo.FileName = "wifi.bat"
                    procInfo.WorkingDirectory = ""
                    procInfo.Verb = "runas"
                    Process.Start(procInfo)
                Catch ex As Exception
                    MessageBox.Show(ex.Message.ToString())
                End Try
               
            End If
        Else
            flag = True
            txtUserName.Enabled = True
            txtPassword.Enabled = True
            Button1.Text = "Start"
            s = "netsh wlan stop hostednetwork"
            RichTextBox1.Text = s
            RichTextBox1.SaveFile(Application.StartupPath + "\wifi.bat", RichTextBoxStreamType.PlainText)

            Try
                Dim procInfo As New ProcessStartInfo()
                procInfo.UseShellExecute = True
                procInfo.FileName = "wifi.bat"
                procInfo.WorkingDirectory = ""
                procInfo.Verb = "runas"
                Process.Start(procInfo)
            Catch ex As Exception
                MessageBox.Show(ex.Message.ToString())
            End Try
           
     
        End If

Explanation of code :

Here we have created one dynamic .bat file and write down all the necessary command for create hotspot and execute it through the programming.


Comments

Popular posts from this blog

Create Short URL using C#