About Wlan connect

Jul 23, 2009 at 3:54 AM

Hi, everybody,

      This is a very perfect API. I have a question here that I don't know how to use the function "Connect(Wlan.WlanConnectionMode connectionMode, Wlan.Dot11BssType bssType, string profile)" to connect to a specific network... How should I set the parameters? Can anyone provide me an example of Connect to a specific network ? thank you very much!

     I have tried the codes bellow, but got the Win32Exception, the error is located at the Connect function, maybe the parameters are invalid.

//=======================================================================

 

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            WlanClient WC = new WlanClient();
            //We must define the flags for using the "GetAvailableNetworkList" function. 
            Wlan.WlanGetAvailableNetworkFlags flag = new Wlan.WlanGetAvailableNetworkFlags();
            //refreshing the network list.
            WC.Interfaces[0].Scan();
            //The array that contains the networks details.
            Wlan.WlanAvailableNetwork[] WList;
            WList = WC.Interfaces[0].GetAvailableNetworkList(flag);
            foreach (Wlan.WlanAvailableNetwork ssid in WList)
            {
                Console.WriteLine("SSID is : " + Encoding.ASCII.GetString(ssid.dot11Ssid.SSID));
                //Console.Read();
            }
            WC.Interfaces[0].Connect(Wlan.WlanConnectionMode.Profile, Wlan.Dot11BssType.Any, null);
        }
    }
}

namespace ConsoleApplication1

{

    class Program

    {

        static void Main(string[] args)

        {

            WlanClient WC = new WlanClient();

 

            //We must define the flags for using the "GetAvailableNetworkList" function. 

            Wlan.WlanGetAvailableNetworkFlags flag = new Wlan.WlanGetAvailableNetworkFlags();

 

            //refreshing the network list.

            WC.Interfaces[0].Scan();

 

            //The array that contains the networks details.

            Wlan.WlanAvailableNetwork[] WList;

 

            WList = WC.Interfaces[0].GetAvailableNetworkList(flag);

            foreach (Wlan.WlanAvailableNetwork ssid in WList)

            {

                Console.WriteLine("SSID is : " + Encoding.ASCII.GetString(ssid.dot11Ssid.SSID));

                //Console.Read();

            }

 

            WC.Interfaces[0].Connect(Wlan.WlanConnectionMode.Profile, Wlan.Dot11BssType.Any, null);

 

        }

    }

}

 

//============================================================

How should I set the parameters? my OS is Windows XP SP3.

 

 

Jul 25, 2009 at 11:23 PM
            string hexssid,xmlprofile;
            hexssid = ConvertToHex(SSID.Text).ToUpper();
            xmlprofile = Properties.Resources.DefaultProfile;
            xmlprofile = xmlprofile.Replace("{SSID}", SSID.Text);
            xmlprofile = xmlprofile.Replace("{SSIDHEX}", hexssid);
            xmlprofile = xmlprofile.Replace("{KEY}", ToConnectKey.Text.ToUpper());
            Interface.SetProfile(Wlan.WlanProfileFlags.AllUser,xmlprofile,true);
            Interface.Connect(Wlan.WlanConnectionMode.Profile, Wlan.Dot11BssType.Any, SSID.Text);
Oct 17, 2010 at 1:47 AM
nicsor wrote:
            string hexssid,xmlprofile;
            hexssid = ConvertToHex(SSID.Text).ToUpper();
            xmlprofile = Properties.Resources.DefaultProfile;
            xmlprofile = xmlprofile.Replace("{SSID}", SSID.Text);
            xmlprofile = xmlprofile.Replace("{SSIDHEX}", hexssid);
            xmlprofile = xmlprofile.Replace("{KEY}", ToConnectKey.Text.ToUpper());
            Interface.SetProfile(Wlan.WlanProfileFlags.AllUser,xmlprofile,true);
            Interface.Connect(Wlan.WlanConnectionMode.Profile, Wlan.Dot11BssType.Any, SSID.Text);

are there missing name space that have to be added ?

like ConvertToHex, Interface, SSID ?