扫一扫
分享文章到微信
扫一扫
关注官方公众号
至顶头条
作者:杨冶军 来源:天极网 2007年10月14日
关键字:
在本页阅读全文(共2页)
Option Explicit /*有关的API声明*/ Private Declare Function RegOpenKeyEx Lib "advapi32" Alias "RegOpenKeyExA" (ByVal hKey As Long, ByVal lpSubKey As String, ByVal ulOptions As Long, ByVal samDesired As Long, phkResult As Long) As Long Private Declare Function RegQueryValueEx Lib "advapi32" Alias "RegQueryValueExA" (ByVal hKey As Long, ByVal lpValueName As String, ByVal lpReserved As Long, ByRef lpType As Long, ByVal szData As String, ByRef lpcbData As Long) As Long Private Declare Function RegCloseKey Lib "advapi32"(ByVal hKey As Long) As Long /*常数的设定*/ Const HKEY_CURRENT_USER = &H80000001 Const ERROR_SUCCESS = 0 在命令按钮(cmdCallConnect)中加入如下代码: Private Sub cmdCallConnect_Click() /*启动默认拨号连接*/ Shell "rundll rnaui.dll,RnaDial" + GetConnect, vbNormalFocus End Sub /*取得连接的函数(GetConnect)*/ Public Function GetConnect() As String Dim hKey As Long Dim SubKey As String /*主键*/ hKey = HKEY_CURRENT_USER /*子键*/ SubKey = "RemoteAccess" /*取得默认连接名*/ GetConnect=GetRegValue(hKey,SubKey, "Default") End Function /*取得注册的函数(GetRegValue)*/ Public Function GetRegValue(hKey As Long,lpszSubKey As String,szKey As String) As Variant On Error GoTo ErrorRoutineErr: Dim phkResult As Long Dim lResult As Long Dim szBuffer As String Dim lBuffSize As Long /*创建缓冲区*/ szBuffer = Space(255) lBuffSize = Len(szBuffer) /*打开注册键*/ RegOpenKeyEx hKey, lpszSubKey, 0, 1,phkResult /*取得查询结果*/ lResult = RegQueryValueEx(phkResult, szKey, 0, 0, szBuffer, lBuffSize) /*关闭注册键*/ RegCloseKey phkResult /*返回结果*/ If lResult = ERROR_SUCCESS Then GetRegValue = Left(szBuffer, lBuffSize - 1) Else GetRegValue ="" End If Exit Function /*意外处理*/ ErrorRoutineErr: GetRegValue ="" End Function |
如果您非常迫切的想了解IT领域最新产品与技术信息,那么订阅至顶网技术邮件将是您的最佳途径之一。