最新下载
热门教程
- 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)
相关文章
- 《彩色点点战争》推图常用三大主c玩法详解 01-23
- 《燕云十六声》池鱼林木任务攻略 01-23
- 《大连地铁e出行》查看行程记录方法 01-23
- 《明日方舟》2025春节限定干员余角色介绍 01-23
- 《崩坏:星穹铁道》万敌光锥搭配攻略 01-23
- 《燕云十六声》一药千金任务攻略 01-23