2017-08-12 67 views
1

该问题似乎很简单,但是我找到的所有解决方案都无效。VB6 - 如何打开Chrome?

我想知道如何自动打开Chrome,我尝试了下面的代码和其他几个解决方案,但是当Chrome完全关闭并且我尝试打开时,它会显示窗口,但它不会打开任何网站。

Private Sub Command1_Click() 
    Shell "C:\Program Files\Google\Chrome\Application\chrome.exe -url https://www.google.com/" 
End Sub 

Chrome crashing

回答

1

这不会有什么用VB6,当然,它是关于Chrome的命令行开关。 Chrome命令行开关以两个破折号开头。所以这应该工作:

Shell "C:\Program Files\Google\Chrome\Application\chrome.exe --url https://www.google.com/" 

Program Files (x86)如果你正在运行64位Windows,自然)

但你并不需要指定开关的URL,这也适用:

Shell "C:\Program Files\Google\Chrome\Application\chrome.exe https://www.google.com/" 

编辑:

它实际上似乎是不存在于Chrome的“网址”开关,所以它是亲每个只需将它自己放在命令行上,就像我上面的第二个shell命令一样。

+0

我我也试过这个,但它也给出了同样的问题。我做了一个测试,创建一个打开Chrome的.bat文件,当我手动运行时,它工作正常,如果我通过VB6运行.bat,它也会产生问题。 –

+1

我刚刚尝试过,对我来说工作正常,无论是作为bat文件还是从vb6代码启动Chrome。 – MarkL

+0

@安德森科斯塔:如果与编程使用完全不同,则使用BAT。不要混淆!使用VB6代码,而不是BAT(如MarkL所写)。另外,你确定Chrome是64位的吗? –

1

您应该确保Chrome.exe的安装位置。 32或64位? 你必须检查才能运行它。

例如,我有一个64位计算机和的chrome.exe是上安装32位版本:

C:\程序文件(x86)\谷歌\铬\应用

的检查代码如下两个32/64位版本:

  1. 打开一个新的项目VBP,在Form1:
  2. 添加命令,名称:cmdOpenChrome
  3. 添加一个TextBox,名称:txtUrl
  4. 复制下面的代码:

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