''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'
' 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.   

    来一个简单的
    ==声明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)
      

  2.   

    我用过这种方法,但是对于IP地址就没用了,比如把"www.csdn.com"换为
    "10.xxx.xxx.xx"就不行了,有什么方法可以解决么?