Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

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

2025-03-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

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.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report