您应该确保Chrome.exe的安装位置。 32或64位? 你必须检查才能运行它。
例如,我有一个64位计算机和的chrome.exe是上安装32位版本:
C:\程序文件(x86)\谷歌\铬\应用
的检查代码如下两个32/64位版本:
- 打开一个新的项目VBP,在Form1:
- 添加命令,名称:cmdOpenChrome
- 添加一个TextBox,名称:txtUrl
- 复制下面的代码:
Option Explicit
Private 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
Public Sub OpenChrome(ByVal pURL As String)
Dim sChromePath As String
Dim sTmp As String
Dim sProgramFiles As String
Dim bNotFound As Boolean
'
' check for 32/64 bit version
'
sProgramFiles = Environ("ProgramFiles")
sChromePath = sProgramFiles & "\Google\Chrome\Application\chrome.exe"
If Dir$(sChromePath) = vbNullString Then
' if not found, search for 32bit version
sProgramFiles = Environ("ProgramFiles(x86)")
If sProgramFiles > vbNullString Then
sChromePath = sProgramFiles & "\Google\Chrome\Application\chrome.exe"
If Dir$(sChromePath) = vbNullString Then
bNotFound = True
End If
Else
bNotFound = True
End If
End If
If bNotFound = True Then
MsgBox "Chrome.exe not found"
Exit Sub
End If
ShellExecute 0, "open", sChromePath, pURL, vbNullString, 1
End Sub
Private Sub cmdOpenChrome_Click()
OpenChrome txtUrl.Text
End Sub
下面使用的样品许多不同的浏览器:
http://nuke.vbcorner.net/Projects/VB60/VB60variousprojects/tabid/79/language/en-US/Default.aspx#OpenURLwithAnyBrowser
我我也试过这个,但它也给出了同样的问题。我做了一个测试,创建一个打开Chrome的.bat文件,当我手动运行时,它工作正常,如果我通过VB6运行.bat,它也会产生问题。 –
我刚刚尝试过,对我来说工作正常,无论是作为bat文件还是从vb6代码启动Chrome。 – MarkL
@安德森科斯塔:如果与编程使用完全不同,则使用BAT。不要混淆!使用VB6代码,而不是BAT(如MarkL所写)。另外,你确定Chrome是64位的吗? –