Get the App
SLTechnology News&Howtos  ›  Development  › 

How does VB.NET initiate a connection in dial-up networking

Shulou Source: shulou.com Published: 2022-06-02 08:49:00 10月05日 Update

This article will explain in detail how VB.NET starts the connection in dial-up network. The editor thinks it is very practical, so I share it with you as a reference. I hope you can get something after reading this article.

VB.NET networking skills case: starting a connection in a Dial-up Network

Because dial-up networking is not an executable file, explorer.exe is needed to start dial-up networking. However, if you want to start a connection in dial-up networking, you need to use two files, rundll.exe and rnaui.dll. The startup method is as follows (assuming this connection name is 163):

Shell "rundll rnaui.dll,RnaDial 163", vbNormalFocus

The connection name is assumed above, but we don't know the connection name in actual programming. Place a command button (cmdCallConnect) on the form to handle the connection in its click event. The following code describes how to get the default connection name and start it:

Option Explicit / * related API statements * / Private Declare Function RegOpenKeyEx Lib "advapi32" Alias "RegOpenKeyExA" (ByVal hKey As Long, ByVal lpSubKey As String, ByVal ulOptions As Long, ByVal samDesired As Long, phkResult As Long) As Long Private Declare Function RegQueryvalueEx Lib "advapi32" Alias "RegQueryvalueExA" (ByVal hKey As Long, ByVal lpvalueName As String, ByVal lpReserved As Long, ByRef lpType As Long, ByVal szData As String ByRef lpcbData As Long) As Long Private Declare Function RegCloseKey Lib "advapi32" (ByVal hKey As Long) As Long / * constant setting * / Const HKEY_CURRENT_USER = & H80000001 Const ERROR_SUCCESS = 0

Add the following code to the command button (cmdCallConnect):

Private Sub cmdCallConnect_Click () / * start the default dial-up connection * / Shell "rundll rnaui.dll,RnaDial" + GetConnect, vbNormalFocus End Sub / * function to get the connection (GetConnect) * / Public Function GetConnect () As String Dim hKey As Long Dim SubKey As String / * Primary key * / hKey = HKEY_CURRENT_USER / * subkey * / SubKey = "RemoteAccess" / * get the default connection name * / GetConnect=GetRegvalue (hKey,SubKey "Default") End Function / * get the registered function (GetRegvalue) * / Public Function GetRegvalue (hKey As Long) LpszSubKey As String SzKey As String) As Variant On Error GoTo ErrorRoutineErr: Dim phkResult As Long Dim lResult As Long Dim szBuffer As String Dim lBuffSize As Long / * create buffer * / szBuffer = Space lBuffSize = Len (szBuffer) / * Open the registration key * / RegOpenKeyEx hKey, lpszSubKey, 0,1 Magi phkResult / * get the query result * / lResult = RegQueryvalueEx (phkResult, szKey, 0,0, szBuffer) LBuffSize) / * close the registration key * / RegCloseKey phkResult / * return result * / If lResult = ERROR_SUCCESS Then GetRegvalue = Left (szBuffer, lBuffSize-1) Else GetRegvalue = "" End If Exit Function / * unexpected handling * / ErrorRoutineErr: GetRegvalue = "End Function on how VB.NET initiates connections in dial-up networks" ends here Hope that the above content can be helpful to you, so that you can learn more knowledge, if you think the article is good, please share it for more people to see.

Tags: Network name article code function command button file more result processing related good practical unexpected two event content actual constant Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Xiaomi vpn Apple Redmi macOS