Click here to Skip to main content
15,879,535 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:

I am trying to write a program to connect to wifi routers/ap. I have been successfull into connecting to open networks.

However when i try to connect to secured networks, a baloon pop up asking for password. Can i not pass the password automatically.

My code is as below. Can someone modify this to work for secured network. My APs does not have any profile names.
/* Client opens a handle for connection */
status = WlanOpenHandle( WLAN_API_VERSION, NULL, &dwCurVersion,&hClient );

/* Get the list of wi-fi interfaces */
status = WlanEnumInterfaces(hClient, NULL, &pIfList);

    pIfInfo = (WLAN_INTERFACE_INFO *) &pIfList->InterfaceInfo[0];

/* Get the list of visible networks */
    status = WlanGetAvailableNetworkList (hClient,&pIfInfo->InterfaceGuid,0,NULL,&pBssList);

    for (tmploop = 0; tmploop < pBssList->dwNumberOfItems; tmploop++)
        pBssEntry = (WLAN_AVAILABLE_NETWORK *) & pBssList->Network[tmploop];
        if (pBssEntry->dot11Ssid.uSSIDLength != 0)

            strcpy(tmpBuffer,(char *) pBssEntry->dot11Ssid.ucSSID );

            /* Whether the HOST to be connected is found ? */
            if(strcmp(tmpBuffer,"2WIRE472") == 0)
                //hostFoundflag = SET;
                wlanConnPara.wlanConnectionMode = wlan_connection_mode_discovery_secure;//wlan_connection_mode_discovery_unsecure;
                wlanConnPara.strProfile = pBssEntry->strProfileName;
                strcpy( (char *)(infoForSSID.ucSSID), tmpBuffer);
                infoForSSID.uSSIDLength = pBssEntry->dot11Ssid.uSSIDLength;
                wlanConnPara.pDot11Ssid =&infoForSSID;
                wlanConnPara.pDesiredBssidList = NULL;
                wlanConnPara.dot11BssType = pBssEntry->dot11BssType;
                wlanConnPara.dwFlags = pBssEntry->dwFlags;

                /* Connect to the host */
                status = WlanConnect( hClient, &pIfInfo->InterfaceGuid, &wlanConnPara, NULL );


Updated 6-Oct-12 18:30pm

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900