2
Vote

How to conntect to ad-hoc network on another computer programatically?

description

Hi,
I want to connect to ad-hoc network on another laptop by using C#, but when I try follow sample code, all I recieve is this make a new ad-hoc network and connect to it. my code is:
        WlanClient client = new WlanClient();
        foreach ( WlanClient.WlanInterface wlanIface in client.Interfaces )
        {
            // Lists all networks with WEP security
            Wlan.WlanAvailableNetwork[] networks = wlanIface.GetAvailableNetworkList( 0 );
            foreach ( Wlan.WlanAvailableNetwork network in networks )
            {
                if ( GetStringForSSID(network.dot11Ssid).Equals( "Cheesecake" ) )
                {
                         // Connects to a known network with WEP security
                        string profileName = "Cheesecake"; // this is also the SSID
                        string mac = "52544131303235572D454137443638";
                        string key = "hello";
                        string profileXml = string.Format( "<?xml version=\"1.0\"?><WLANProfile xmlns=\"http://www.microsoft.com/networking/WLAN/profile/v1\"><name>{0}</name><SSIDConfig><SSID><hex>{1}</hex><name>{0}</name></SSID></SSIDConfig><connectionType>IBSS</connectionType><MSM><security><authEncryption><authentication>open</authentication><encryption>WEP</encryption><useOneX>false</useOneX></authEncryption><sharedKey><keyType>networkKey</keyType><protected>false</protected><keyMaterial>{2}</keyMaterial></sharedKey><keyIndex>0</keyIndex></security></MSM></WLANProfile>", profileName, mac, key );
                        wlanIface.SetProfile( Wlan.WlanProfileFlags.AllUser, profileXml, true );
                       wlanIface.Connect( Wlan.WlanConnectionMode.Profile, Wlan.Dot11BssType.Any, profileName );
                       Console.ReadLine();

        }
How I can connect to ad-hoc network that on another computer. This code is make a new ad-hoc on this computer and connect them only. What I made a misstake?

comments