用程序实现自动拨号
用程序实现自动拨号屠恩海(SunHai)
开发工具:Microsoft Visual Studio .NET 2003
操作系统:Windows XP
在编写网络程序时很可能用到自动拨号。比如,邮件易做图用自动断线和拨号实现本机IP地址的更换。
要实现自动拨号,分两步:
从注册表读取本机拨号链接名称;
自动拨号。
调用API函数从注册表读取本机拨号链接名
以前,我调用API函数从注册表中读取本机拨号链接名称。
在Module中用如下代码:
Private Declare Function RegOpenKey Lib "advapi32.dll" Alias "RegOpenKeyA" (ByVal hKey As Integer, ByVal lpSubKey As String, ByRef phkResult As Integer) As Integer
Private Declare Function RegCloseKey Lib "advapi32.dll" (ByVal hKey As Integer) As Integer
Private Declare Function RegEnumKey Lib "advapi32.dll" Alias "RegEnumKeyA" (ByVal hKey As Integer, ByVal dwIndex As Integer, ByVal lpName As String, ByVal cbName As Integer) As Integer
Const HKEY_CURRENT_USER As Integer = &H80000001
Const ERROR_NO_MORE_ITEMS As Short = 259
Const ERROR_SUCCESS As Short = 0
Dim hKey As Integer
Dim i As Integer
Dim astr As String = New String("", 256)
If RegOpenKey(HKEY_CURRENT_USER, "RemoteAccessProfile", hKey) = ERROR_SUCCESS Then
While RegEnumKey(hKey, i, astr, 256) = ERROR_SUCCESS
MsgBox(astr) '链接名称
i += 1
End While
RegCloseKey(hKey)
补充:asp.net教程,远程及网络应用