''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'
' Public Method GetRegistryKey
'
' This function is designed to retrieve a registry key from a particular
' section of the registry. Instead of making the caller worry about the
' various constants that specify each of the hives, this function has
' optional Boolean arguments that can be set in order to select a particular
' hive.
'
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Modification History
' Date Description
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''Public Function GetRegistryKey(sKey As String, sEntry As String, _
Optional bHKeyClassesRoot As Boolean = False, _
Optional bHKeyCurrentConfig As Boolean = False, _
Optional bHKeyCurrentUser As Boolean = True, _
Optional bHKeyDynamicData As Boolean = False, _
Optional bHKeyLocalMachine As Boolean = False, _
Optional bHKeyPerformanceData As Boolean = False, _
Optional bHKeyUsers As Boolean = False, _
Optional bDirectory As Boolean = False) As String
Const BUFFER_LENGTH = 255
Dim sKeyName As String
Dim sReturnBuffer As String
Dim lBufLen As Long
Dim lReturn As Long
Dim hKeyHandle As Long
Dim lKeyType As Long
'
' Set up return buffer
'
sReturnBuffer = Space(BUFFER_LENGTH)
lBufLen = BUFFER_LENGTH
lKeyType = DetermineKeyType(bHKeyClassesRoot, _
bHKeyCurrentConfig, _
bHKeyCurrentUser, _
bHKeyDynamicData, _
bHKeyLocalMachine, _
bHKeyPerformanceData, _
bHKeyUsers)
lReturn = RegOpenKeyEx(lKeyType, sKey, _
0, KEY_ALL_ACCESS, hKeyHandle)
If lReturn = ERROR_SUCCESS Then
lReturn = RegQueryValueExString(hKeyHandle, sEntry, _
0, 0, sReturnBuffer, lBufLen)
If lReturn = ERROR_SUCCESS Then
'
' Have to remove the null terminator at end of string
'
sReturnBuffer = Trim$(Left$(sReturnBuffer, lBufLen - 1))
'
' Add a backslash if one isn't already on a
' directory entry.
'
If bDirectory Then
If Right$(sReturnBuffer, 1) <> "\" Then
sReturnBuffer = sReturnBuffer & "\"
End If
End If
GetRegistryKey = sReturnBuffer
Else
GetRegistryKey = ""
End If
Else
GetRegistryKey = ""
End If
'
' Close the key
'
RegCloseKey hKeyHandle
End Function
Public Function OpenWebSite(WebSiteAddress As String) As Boolean
OpenWebSite = FalseOn Error GoTo ErrTrap
Shell GetRegistryKey("HTMLFile\Shell\Open\Command", "", bHKeyClassesRoot:=True) & WebSiteAddress, vbMaximizedFocusOpenWebSite = True
ErrTrap:
On Error GoTo 0End Function调用OpenWebSite()即可
如 OpenWebSite "www.csdn.com"
'
' Public Method GetRegistryKey
'
' This function is designed to retrieve a registry key from a particular
' section of the registry. Instead of making the caller worry about the
' various constants that specify each of the hives, this function has
' optional Boolean arguments that can be set in order to select a particular
' hive.
'
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Modification History
' Date Description
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''Public Function GetRegistryKey(sKey As String, sEntry As String, _
Optional bHKeyClassesRoot As Boolean = False, _
Optional bHKeyCurrentConfig As Boolean = False, _
Optional bHKeyCurrentUser As Boolean = True, _
Optional bHKeyDynamicData As Boolean = False, _
Optional bHKeyLocalMachine As Boolean = False, _
Optional bHKeyPerformanceData As Boolean = False, _
Optional bHKeyUsers As Boolean = False, _
Optional bDirectory As Boolean = False) As String
Const BUFFER_LENGTH = 255
Dim sKeyName As String
Dim sReturnBuffer As String
Dim lBufLen As Long
Dim lReturn As Long
Dim hKeyHandle As Long
Dim lKeyType As Long
'
' Set up return buffer
'
sReturnBuffer = Space(BUFFER_LENGTH)
lBufLen = BUFFER_LENGTH
lKeyType = DetermineKeyType(bHKeyClassesRoot, _
bHKeyCurrentConfig, _
bHKeyCurrentUser, _
bHKeyDynamicData, _
bHKeyLocalMachine, _
bHKeyPerformanceData, _
bHKeyUsers)
lReturn = RegOpenKeyEx(lKeyType, sKey, _
0, KEY_ALL_ACCESS, hKeyHandle)
If lReturn = ERROR_SUCCESS Then
lReturn = RegQueryValueExString(hKeyHandle, sEntry, _
0, 0, sReturnBuffer, lBufLen)
If lReturn = ERROR_SUCCESS Then
'
' Have to remove the null terminator at end of string
'
sReturnBuffer = Trim$(Left$(sReturnBuffer, lBufLen - 1))
'
' Add a backslash if one isn't already on a
' directory entry.
'
If bDirectory Then
If Right$(sReturnBuffer, 1) <> "\" Then
sReturnBuffer = sReturnBuffer & "\"
End If
End If
GetRegistryKey = sReturnBuffer
Else
GetRegistryKey = ""
End If
Else
GetRegistryKey = ""
End If
'
' Close the key
'
RegCloseKey hKeyHandle
End Function
Public Function OpenWebSite(WebSiteAddress As String) As Boolean
OpenWebSite = FalseOn Error GoTo ErrTrap
Shell GetRegistryKey("HTMLFile\Shell\Open\Command", "", bHKeyClassesRoot:=True) & WebSiteAddress, vbMaximizedFocusOpenWebSite = True
ErrTrap:
On Error GoTo 0End Function调用OpenWebSite()即可
如 OpenWebSite "www.csdn.com"
解决方案 »
- 几个记事本问题:1转到指定行,2查找功能,3打开任意文件以文本显示在text中
- 讨论:变量定义
- “!!!!!!100分!!!!!”使用VB自带的sysTray实现托盘,想制作气泡效果,有做过的进来 。
- excel 关闭的问题,在线等!!!!!问题解决就给分,高手多谢指点!!!
- VSFlexGrid控件的三个问题.
- 没有为命令对象设置命令???????????高分求解!!
- vb如何做计算器
- ADO的简单问题,100分!
- 怎样编程实现每隔几天(如2)在某一个固定时刻(如10:00)执行一个操作
- 再问
- 请问有哪位大侠用过WNetAddConnection这个东东?
- 怎样复制一个已经打开的数据库文件?
==声明API==
Public Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long ==调用==
s = ShellExecute(hwnd, "open", "www.csdn.com", vbNullString, vbNullString, SW_RESTORE)
"10.xxx.xxx.xx"就不行了,有什么方法可以解决么?