最新下载
热门教程
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
用程序实现自动拨号
时间:2008-01-12 编辑:简简单单 来源:一聚教程网
用程序实现自动拨号
屠恩海(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)
相关文章
- 让Java程序自动重启的实现方法 06-07
- 一款自动竞拍出价程序 11-14
- 浅谈自动采集程序及入库 01-18
- C#复制数组的两种方式及效率比较解读 10-24
- ASP.NET Identity用法解析 10-24
- ASP.NET MVC使用Identity增删改查用户介绍 10-24