最新下载
热门教程
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
用程序实现自动拨号
时间:2022-07-02 12:04:28 编辑:袖梨 来源:一聚教程网
用程序实现自动拨号
屠恩海(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)
屠恩海(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)
相关文章
- 《塞尔达传说王国之泪》海利亚盾刷新耐久方法 海利亚盾怎么刷新耐久? 05-03
- 崩坏星穹铁道托帕突破材料一览 05-03
- TokenPocket钱包苹果版 05-03
- kdpay钱包app官网下载安卓版 05-03
- MGC钱包下载2024最新版 05-03
- 黑币钱包中文版 05-03