в заголовке: #include <Ras.h>
RASENTRY rasEntry;
RASDIALPARAMS res;
HRASCONN hRasConn = NULL;
memset(&rasEntry, 0, sizeof(RASENTRY));
memset(&res, 0, sizeof(RASDIALPARAMS));
res.dwSize = sizeof(res);
rasEntry.dwSize = sizeof(rasEntry);
rasEntry.dwfOptions = RASEO_PreviewUserPw | RASEO_ShowDialingProgress | RASEO_Custom | RASEO_RequireMsCHAP2 ;
rasEntry.dwfOptions2=RASEO2_DisableNbtOverIP| RASEO2_ReconnectIfDropped | RASEO2_Internet;
rasEntry.dwfNetProtocols = RASNP_Ip;
rasEntry.dwRedialCount=99999;
rasEntry.dwRedialPause=3;
rasEntry.dwEncryptionType=ET_None;
rasEntry.dwType=RASET_Vpn;
rasEntry.dwVpnStrategy=VS_PptpFirst;
strcpy(rasEntry.szLocalPhoneNumber, TEXT("195.160.61.200"));
strcpy(rasEntry.szDeviceType, RASDT_Vpn);
strcpy(rasEntry.szDeviceName, TEXT("VPN"));
strcpy(res.szEntryName, TEXT("VPN"));
strcpy(res.szUserName, TEXT("user"));
strcpy(res.szPassword, TEXT("Password"));
BOOL PwdDetected = false;
if (RasSetEntryProperties(NULL, TEXT("VPN"), &rasEntry, sizeof(rasEntry), NULL, 0))
{
MessageBox(0,"RasSetEntryProperties failed", 0,0);
}
else MessageBox(0,"Создано VPN соединение","Ok",0);
if (RasSetEntryDialParams(NULL,&res,false))
{
MessageBox(0,"RasSetEntryDialParams", 0,0);
}
else MessageBox(0,"Отредактировано","Ok",0);
RasDial(0, 0, &res, NULL, NULL, &hRasConn);
Как добавить szUserName и szPassword
Нашел код создающий программно VPN-соединения...
вот код:
RASENTRY rasEntry;
memset(&rasEntry, 0, sizeof(RASENTRY));
rasEntry.dwSize = sizeof(rasEntry);
rasEntry.dwfOptions = RASEO_PreviewUserPw | RASEO_ShowDialingProgress | RASEO_Custom | RASEO_RequireMsCHAP2 ;
rasEntry.dwfOptions2=RASEO2_DisableNbtOverIP| RASEO2_ReconnectIfDropped | RASEO2_Internet;
rasEntry.dwRedialCount=99999;
rasEntry.dwRedialPause=3;
rasEntry.dwEncryptionType=ET_Optional;
rasEntry.dwType=RASET_Vpn;
strcpy(rasEntry.szLocalPhoneNumber, TEXT("vpn.prudok.ru"));
strcpy(rasEntry.szDeviceType, RASDT_Vpn);
strcpy(rasEntry.szDeviceName, TEXT("VPN"));
Не могу справиться с одной задачей, как прописать в создавшийся объект имя пользователя и пароль.
Как я выяснил в MSDN функция RASENTRY, не может этого сделать сделать это может RASDIALPARAMS.
Цитата:
When retrieving the password using the RasGetEntryDialParams function, the szPassword member does not receive the actual password. Instead, szPassword receives a handle to the saved password. Substitute this handle for the saved password in calls to RasSetEntryDialParams, and RasDial. When presented with this handle, RasDial retrieves and uses the saved password. The value of this handle may change in future versions of the operating system; do not develop code that depends on the contents or format of this value.
Всем спасибо за помощь. Рабочий Код:
и добавить туда нечто подобное:
RASDIALPARAMS rasdpEntry;
rasdpEntry.szUsername = new TCHAR[256];
lstrcpy(rasdpEntry.szUsername, szUserName);
rasdpEntry.szPassword = new TCHAR[256];
lstrcpy(rasdpEntry.szPassword, szPassword);
и добавить туда нечто подобное:
RASDIALPARAMS rasdpEntry;
rasdpEntry.szUsername = new TCHAR[256];
lstrcpy(rasdpEntry.szUsername, szUserName);
rasdpEntry.szPassword = new TCHAR[256];
lstrcpy(rasdpEntry.szPassword, szPassword);
Пробовал не помогает, VPN создается без указания Имени пользователя и пароля...((
добавляю
RASDIALPARAMS rasdpEntry;
rasdpEntry.dwSize = sizeof(rasdpEntry);
lstrcpy(rasdpEntry.szUserName, TEXT("user"));
lstrcpy(rasdpEntry.szPassword, TEXT("password"));
Код:
RASENTRY rasEntry;
RASDIALPARAMS res;
memset(&rasEntry, 0, sizeof(RASENTRY));
memset(&res, 0, sizeof(RASDIALPARAMS));
res.dwSize = sizeof(res);
rasEntry.dwSize = sizeof(rasEntry);
rasEntry.dwfOptions = RASEO_PreviewUserPw | RASEO_ShowDialingProgress | RASEO_Custom | RASEO_RequireMsCHAP2 ;
rasEntry.dwfOptions2=RASEO2_DisableNbtOverIP| RASEO2_ReconnectIfDropped | RASEO2_Internet;
rasEntry.dwRedialCount=99999;
rasEntry.dwRedialPause=3;
rasEntry.dwEncryptionType=ET_Optional;
rasEntry.dwType=RASET_Vpn;
strcpy(rasEntry.szLocalPhoneNumber, TEXT("vpn.prudok.ru"));
strcpy(rasEntry.szDeviceType, RASDT_Vpn);
strcpy(rasEntry.szDeviceName, TEXT("VPN"));
strcpy(res.szEntryName, TEXT("VPN"));
strcpy(res.szUserName, TEXT("user"));
strcpy(res.szPassword, TEXT("password"));
if (RasSetEntryProperties(NULL, TEXT("VPN"), &rasEntry, sizeof(rasEntry), NULL, 0))
{
MessageBox(0,"RasSetEntryProperties failed", 0,0);
}
else MessageBox(0,"Создано VPN соединение","Ok",0);
if (RasSetEntryDialParams(NULL, &res,false))
{
MessageBox(0,"RasSetEntryProperties failed", 0,0);
}
else MessageBox(0,"Отредактировано","Ok",0);
RASDIALPARAMS res;
memset(&rasEntry, 0, sizeof(RASENTRY));
memset(&res, 0, sizeof(RASDIALPARAMS));
res.dwSize = sizeof(res);
rasEntry.dwSize = sizeof(rasEntry);
rasEntry.dwfOptions = RASEO_PreviewUserPw | RASEO_ShowDialingProgress | RASEO_Custom | RASEO_RequireMsCHAP2 ;
rasEntry.dwfOptions2=RASEO2_DisableNbtOverIP| RASEO2_ReconnectIfDropped | RASEO2_Internet;
rasEntry.dwRedialCount=99999;
rasEntry.dwRedialPause=3;
rasEntry.dwEncryptionType=ET_Optional;
rasEntry.dwType=RASET_Vpn;
strcpy(rasEntry.szLocalPhoneNumber, TEXT("vpn.prudok.ru"));
strcpy(rasEntry.szDeviceType, RASDT_Vpn);
strcpy(rasEntry.szDeviceName, TEXT("VPN"));
strcpy(res.szEntryName, TEXT("VPN"));
strcpy(res.szUserName, TEXT("user"));
strcpy(res.szPassword, TEXT("password"));
if (RasSetEntryProperties(NULL, TEXT("VPN"), &rasEntry, sizeof(rasEntry), NULL, 0))
{
MessageBox(0,"RasSetEntryProperties failed", 0,0);
}
else MessageBox(0,"Создано VPN соединение","Ok",0);
if (RasSetEntryDialParams(NULL, &res,false))
{
MessageBox(0,"RasSetEntryProperties failed", 0,0);
}
else MessageBox(0,"Отредактировано","Ok",0);
Цитата: kot_
вероятно причина в том, что это поле используется только для отправки пасса на сервер. пароль там не хранится. О чем кстати и пишется в доках:
Цитата:
When retrieving the password using the RasGetEntryDialParams function, the szPassword member does not receive the actual password. Instead, szPassword receives a handle to the saved password. Substitute this handle for the saved password in calls to RasSetEntryDialParams, and RasDial. When presented with this handle, RasDial retrieves and uses the saved password. The value of this handle may change in future versions of the operating system; do not develop code that depends on the contents or format of this value.
Спасибо, понял. А как передать этот пароль с подключением, или он как то по другому отправляется.
Делаю вот так:
Код:
RASENTRY rasEntry;
RASDIALPARAMS res;
HRASCONN hRasConn = NULL;
memset(&rasEntry, 0, sizeof(RASENTRY));
memset(&res, 0, sizeof(RASDIALPARAMS));
res.dwSize = sizeof(res);
rasEntry.dwSize = sizeof(rasEntry);
rasEntry.dwfOptions = RASEO_PreviewUserPw | RASEO_ShowDialingProgress | RASEO_Custom | RASEO_RequireMsCHAP2 ;
rasEntry.dwfOptions2=RASEO2_DisableNbtOverIP| RASEO2_ReconnectIfDropped | RASEO2_Internet;
rasEntry.dwfNetProtocols = RASNP_Ip;
rasEntry.dwRedialCount=99999;
rasEntry.dwRedialPause=3;
rasEntry.dwEncryptionType=ET_Optional;
rasEntry.dwType=RASET_Vpn;
strcpy(rasEntry.szLocalPhoneNumber, TEXT("195.16.60.200"));
strcpy(rasEntry.szDeviceType, RASDT_Vpn);
strcpy(rasEntry.szDeviceName, TEXT("VPN"));
strcpy(res.szEntryName, TEXT("VPN"));
strcpy(res.szUserName, TEXT("User"));
strcpy(res.szPassword, TEXT("123"));
if (RasSetEntryProperties(NULL, TEXT("VPN"), &rasEntry, sizeof(rasEntry), NULL, 0))
{
MessageBox(0,"RasSetEntryProperties failed", 0,0);
}
else MessageBox(0,"Создано VPN соединение","Ok",0);
if (RasSetEntryDialParams(NULL,&res,false))
{
MessageBox(0,"RasSetEntryDialParams", 0,0);
}
else MessageBox(0,"Отредактировано","Ok",0);
RasDial(NULL, NULL, &res, NULL, NULL, &hRasConn);
RASDIALPARAMS res;
HRASCONN hRasConn = NULL;
memset(&rasEntry, 0, sizeof(RASENTRY));
memset(&res, 0, sizeof(RASDIALPARAMS));
res.dwSize = sizeof(res);
rasEntry.dwSize = sizeof(rasEntry);
rasEntry.dwfOptions = RASEO_PreviewUserPw | RASEO_ShowDialingProgress | RASEO_Custom | RASEO_RequireMsCHAP2 ;
rasEntry.dwfOptions2=RASEO2_DisableNbtOverIP| RASEO2_ReconnectIfDropped | RASEO2_Internet;
rasEntry.dwfNetProtocols = RASNP_Ip;
rasEntry.dwRedialCount=99999;
rasEntry.dwRedialPause=3;
rasEntry.dwEncryptionType=ET_Optional;
rasEntry.dwType=RASET_Vpn;
strcpy(rasEntry.szLocalPhoneNumber, TEXT("195.16.60.200"));
strcpy(rasEntry.szDeviceType, RASDT_Vpn);
strcpy(rasEntry.szDeviceName, TEXT("VPN"));
strcpy(res.szEntryName, TEXT("VPN"));
strcpy(res.szUserName, TEXT("User"));
strcpy(res.szPassword, TEXT("123"));
if (RasSetEntryProperties(NULL, TEXT("VPN"), &rasEntry, sizeof(rasEntry), NULL, 0))
{
MessageBox(0,"RasSetEntryProperties failed", 0,0);
}
else MessageBox(0,"Создано VPN соединение","Ok",0);
if (RasSetEntryDialParams(NULL,&res,false))
{
MessageBox(0,"RasSetEntryDialParams", 0,0);
}
else MessageBox(0,"Отредактировано","Ok",0);
RasDial(NULL, NULL, &res, NULL, NULL, &hRasConn);
Либо может кто знает другой вариант передачи пароля VPN соединению?
Код:
RASDIALPARAMS params;
params.dwSize = sizeof(params);
strcpy(params.szEntryName, PBEntry.c_str());
//Юзаем сохраненный пароль
BOOL PwdDetected = FALSE;
//Заполняем структуру
DWORD Result = fRasGetEntryDialParams(NULL,¶ms,&PwdDetected);
params.dwSize = sizeof(params);
strcpy(params.szEntryName, PBEntry.c_str());
//Юзаем сохраненный пароль
BOOL PwdDetected = FALSE;
//Заполняем структуру
DWORD Result = fRasGetEntryDialParams(NULL,¶ms,&PwdDetected);
http://varkon.biz/2008/11/dozvon-s-ispolzovaniem-winapi-ras-funktsii-borland-builder-c/