0 Replies - 521 Views - Last Post: 01 October 2017 - 08:53 AM Rate Topic: -----

#1 mic6  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 01-October 17

How to save my wlan settings?

Posted 01 October 2017 - 08:53 AM

I'm currently using Visual Studio 2012. My form code is given below with design screenshots. I am trying to make a virtual hotspot for my PC but I want to add one feature which saves previous SSID and password and the user dont bother to enter details every time they run it. But My hotspot opens every time with blank text.

Here's my form design:

Form1 Design:
Posted Image

Form1 Coding:
Imports System.Runtime.InteropServices
Imports System.Collections.ObjectModel
Imports System.Text
Imports NativeWifi

Public Class Form1
Public Const WM_NCLBUTTONDOWN As Integer = &HA1
Public Const HT_CAPTION As Integer = &H2`


   <DllImportAttribute("user32.dll")> _
    Public Shared Function SendMessage(ByVal hWnd As IntPtr, _
      ByVal Msg As Integer, ByVal wParam As Integer, _
      ByVal lParam As Integer) As Integer
    End Function

    <DllImportAttribute("user32.dll")> _
    Public Shared Function ReleaseCapture() As Boolean
    End Function`

    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        Dim wlan = New WlanClient()
        Dim connectedSsids As Collection(Of [String]) = New Collection(Of String)()

        For Each wlanInterface As WlanClient.WlanInterface In wlan.Interfaces
            Dim ssid As Wlan.Dot11Ssid = wlanInterface.CurrentConnection.wlanAssociationAttributes.dot11Ssid
            connectedSsids.Add(New [String](Encoding.ASCII.GetChars(ssid.SSID, 0, CInt(ssid.SSIDLength))))

            For Each item As String In connectedSsids
                Label1.Text = item
            Next
        Next
    End Sub

    Private Sub Form1_MouseDown(ByVal sender As Object, _
      ByVal e As System.Windows.Forms.MouseEventArgs) _
      Handles Me.MouseDown
        If e.Button = Windows.Forms.MouseButtons.Left Then
            ReleaseCapture()
            SendMessage(Handle, WM_NCLBUTTONDOWN, _
               HT_CAPTION, 0)
        End If
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Try
            If Form2.TextBox1.Text = "" Then
                MsgBox("Hotspot name cant be empty", MsgBoxStyle.Critical)
            End If
            If Form2.TextBox2.TextLength < 8 Then
                MsgBox("Password should be 8+ character", MsgBoxStyle.Critical)
                If Form2.TextBox2.Text = "" Then
                    MsgBox("Password cant be empty", MsgBoxStyle.Critical)
                End If
            Else
                Dim process As New Process()
                process.StartInfo.Verb = "runas"
                process.StartInfo.UseShellExecute = True
                process.Start("cmd", String.Format("/c {0} & {1} & {2}", "netsh wlan set hostednetwork mode=allow ssid=" & Form2.TextBox1.Text & " key=" & Form2.TextBox2.Text, "netsh wlan start hostednetwork", "pause"))
                Form2.CheckBox1.Enabled = False
                Form2.TextBox1.Enabled = False
                Form2.TextBox2.Enabled = False

                MsgBox("Hotspot started Successfully", MsgBoxStyle.Information)
            End If

        Catch
            MsgBox("Failed to Establish a hotspot", MsgBoxStyle.Exclamation)
        End Try
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        Process.Start("CMD", "/C netsh wlan stop hostednetwork")
        Form2.CheckBox1.Enabled = True
        Form2.TextBox1.Enabled = True
        Form2.TextBox2.Enabled = True
        MsgBox("Hotspot stopped Successfully", MsgBoxStyle.Information)
    End Sub

    Private Sub Clsbtn_Click(sender As Object, e As EventArgs) Handles Clsbtn.Click
        Me.Close()
    End Sub

    Private Sub Minbtn_Click(sender As Object, e As EventArgs) Handles Minbtn.Click
        Me.WindowState = System.Windows.Forms.FormWindowState.Minimized
    End Sub

    Private Sub Button3_Click_1(sender As Object, e As EventArgs) Handles Button3.Click
        Me.Hide()
        Form2.Show()
    End Sub
End Class



Form2 Design:

Posted Image

Form2 Code:

Public Class Form2

    Private Sub CheckBox1_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckBox1.CheckedChanged
        If CheckBox1.CheckState = CheckState.Checked Then
            TextBox2.UseSystemPasswordChar = False
            TextBox2.Enabled = False
        End If
        If CheckBox1.CheckState = CheckState.Unchecked Then
            TextBox2.UseSystemPasswordChar = True
            TextBox2.Enabled = True
        End If
    End Sub

    Private Sub SaveBtn_Click_1(sender As Object, e As EventArgs) Handles SaveBtn.Click
        Me.Hide()
        Form1.Show()
    End Sub
End Class



please Help me ASAP im really stuck for a long time and thanks in advance for helping me.

Is This A Good Question/Topic? 0
  • +

Page 1 of 1