Создать ярлык VPN подключения

Discussion in 'С/С++, C#, Rust, Swift, Go, Java, Perl, Ruby' started by FreShBY, 27 Jun 2011.

  1. FreShBY

    FreShBY Banned

    Joined:
    3 May 2009
    Messages:
    24
    Likes Received:
    3
    Reputations:
    0
    Второй день бьюсь с этим вопросом и никак не могу найти решение. Может кто знает? На С#
     
  2. sn0w

    sn0w Статус пользователя:

    Joined:
    26 Jul 2005
    Messages:
    1,023
    Likes Received:
    1,310
    Reputations:
    327
    не в тему, но добавлю (завалялось) коннект-дисконнект впн.

    синтаксис простой: имя_соединения, логин, пасс

    Code:
    //---------------------------------------------------------------------------
    HRASCONN connect_VPN(wchar_t* conn_name, wchar_t* szUser, wchar_t* szPass)
    {
    	RASDIALPARAMSW dial_params;
    	HRASCONN connection;
    
    	memset(&dial_params, 0, sizeof(dial_params));
    	dial_params.dwSize = sizeof(RASDIALPARAMSW);
    
    	lstrcpyW(dial_params.szEntryName, conn_name);
    	lstrcpyW(dial_params.szUserName, szUser);
    	lstrcpyW(dial_params.szPassword, szPass);
    
    	connection = NULL;
    
    	if(RasDialW(NULL, NULL, &dial_params, 0, NULL, &connection) == ERROR_SUCCESS)
    	{
    		return connection;
    	}
    
    	return NULL;
    }
    
    //---------------------------------------------------------------------------
    void disconnect_VPN(wchar_t* conn_name)
    {
    	DWORD dwCb = 0;
    	DWORD dwRet = ERROR_SUCCESS;
    	DWORD dwConnections = 0;
    	LPRASCONNW lpRasConn = NULL;
    
    	dwRet = RasEnumConnectionsW(lpRasConn, &dwCb, &dwConnections);
    
    	if (dwRet == ERROR_BUFFER_TOO_SMALL){
    
    		lpRasConn = (LPRASCONNW) HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, dwCb);
    		lpRasConn[0].dwSize = sizeof(RASCONN);
    		dwRet = RasEnumConnectionsW(lpRasConn, &dwCb, &dwConnections);
    
    		if (ERROR_SUCCESS == dwRet)
    			for (DWORD i = 0; i < dwConnections; i++)
    					   if(!lstrcmpW(lpRasConn[i].szEntryName, conn_name))
    					   {
    						   RasHangUp(lpRasConn[i].hrasconn);
    						   break;
    					   }
    
    		//Deallocate memory for the connection buffer
    		HeapFree(GetProcessHeap(), 0, lpRasConn);
    		lpRasConn = NULL;
    	}
    
    
    }
    
    
     
    1 person likes this.