Shell VB6-如何打开Chrome?
问题似乎很简单,但我找到的所有解决方案都不起作用 我想知道如何自动打开Chrome,我尝试了下面的代码和其他几种解决方案,但当Chrome完全关闭并尝试打开时,它会显示窗口,但不会打开任何网站Shell VB6-如何打开Chrome?,shell,google-chrome,vb6,Shell,Google Chrome,Vb6,问题似乎很简单,但我找到的所有解决方案都不起作用 我想知道如何自动打开Chrome,我尝试了下面的代码和其他几种解决方案,但当Chrome完全关闭并尝试打开时,它会显示窗口,但不会打开任何网站 Private Sub Command1_Click() Shell "C:\Program Files\Google\Chrome\Application\chrome.exe -url https://www.google.com/" End Sub 这与VB6没有任何关系,当然,这是关于C
Private Sub Command1_Click()
Shell "C:\Program Files\Google\Chrome\Application\chrome.exe -url https://www.google.com/"
End Sub
这与VB6没有任何关系,当然,这是关于Chrome命令行开关的。Chrome命令行开关以两个破折号开始。因此,这应该是可行的:
Shell "C:\Program Files\Google\Chrome\Application\chrome.exe --url https://www.google.com/"
(程序文件(x86)
如果您运行的是64位Windows,自然)
但您不需要为url指定开关,这也可以:
Shell "C:\Program Files\Google\Chrome\Application\chrome.exe https://www.google.com/"
编辑:
实际上,Chrome似乎没有“url”开关,因此只需将url放在自己的命令行上就可以了,就像上面我的第二个shell命令一样。您应该确保Chrome.exe安装在何处。32位还是64位? 在运行它之前,您必须进行检查 例如,我有一台64位计算机,Chrome.exe的32位版本安装在: C:\ProgramFiles(x86)\Google\Chrome\Application 下面的代码检查32/64位版本:
下面的示例使用许多不同的浏览器:
我也尝试过,但它也会出现同样的问题。我做了一个创建一个打开Chrome的.bat文件的测试,当我手动运行时,它工作正常,如果我通过VB6运行.bat,它也会出现问题。我刚刚尝试过,它对我来说很好,无论是作为一个bat文件还是从VB6代码启动Chrome。@Anderson Costa:如果以编程方式使用bat,那么使用bat是完全不同的。别搞混了!使用VB6代码,而不是BAT(如MarkL所写)。另外,你确定Chrome是64位的吗?
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