最新下载
热门教程
- 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)
相关文章
- 《无限暖暖》天星之羽获得位置介绍 12-20
- 《流放之路2》重铸台解锁方法介绍 12-20
- 《无限暖暖》瞄准那个亮亮的成就怎么做 12-20
- 《无限暖暖》魔气怪终结者完成方法 12-20
- 《无限暖暖》曙光毛团获得位置介绍 12-20
- 《无限暖暖》日光果获得位置介绍 12-20