【问题标题】:Process.Start() with arguments to start Google ChromeProcess.Start() 带有启动 Google Chrome 的参数
【发布时间】:2013-07-01 00:37:58
【问题描述】:

我正在尝试从带有参数的 .NET 程序启动 Google Chrome 浏览器。但我的行为很奇怪。

以下命令从命令行以“incognito”模式启动 Chrome。它工作正常。

"C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" --incognito

但以下内容在 .NET 中不起作用。 Chrome 确实打开了,但没有隐身,它转到这个奇怪的 URL:http://xn---incognito-nu6e/

Module Module1
    Sub Main()
        System.Diagnostics.Process.Start("C:\Program Files (x86)\Google\Chrome\Application\chrome.exe", "–-incognito")
    End Sub
End Module

【问题讨论】:

    标签: .net shell google-chrome process process.start


    【解决方案1】:

    您可以在调用chrome.exe 时使用快捷方式,而不是使用完整路径位置。

    Module Module1
        Sub Main()
            System.Diagnostics.Process.Start("chrome.exe", "--incognito")
        End Sub
    End Module
    

    更多:start-google-chrome-from-run-windows-key-r

    更新

    我在您的代码中发现了您的问题。 您的代码在参数中使用了–-incognito,但应该是--incognito

    查看该参数中的第一个字符。应该是- 而不是

    Module Module1
        Sub Main()
            System.Diagnostics.Process.Start("C:\Program Files (x86)\Google\Chrome\Application\chrome.exe", "--incognito")
        End Sub
    End Module
    

    【讨论】:

    • 所以,在我根据您提供的链接修改注册表之前,我能够在 .NET 中使用短名称“chrome.exe”,但参数搞砸了。现在我已经修改了注册表项(通过将%1 添加到Default 键),现在我无法使用短名称“chrome.exe”,因为它没有找到,但我必须使用完整路径.然而,这些论点现在运作良好,就像他们应该的那样。那么,为什么我现在不能使用简称?
    • 这些字符在我的屏幕上显示相同,都是“减号”字符。你能澄清一下吗?
    • 出现在我的浏览器中。 :)。我只是复制你的代码。尝试复制我的代码
    • 哇,我不得不在十六进制编辑器中查看差异。我一定是从一开始就从网络浏览器中复制了这个烂摊子,并且从未更改过它。现在可以使用了,谢谢!
    【解决方案2】:

    您也可以从注册表中读取 chrome 路径:

        public static string GetChromePath()
        {
            string lPath = null;
            try
            {
                var lTmp = Registry.GetValue(@"HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\App Paths\chrome.exe", "", null);
                if (lTmp != null)
                    lPath = lTmp.ToString();
                else
                {
                    lTmp = Registry.GetValue(@"HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\App Paths\chrome.exe", "", null);
                    if (lTmp != null)
                        lPath = lTmp.ToString();
                }
            }
            catch (Exception lEx)
            {
                Logger.Error(lEx);
            }
    
            if (lPath == null)
            {
                Logger.Warn("Chrome install path not found! Returning hardcoded path");
                lPath = @"C:\Program Files (x86)\Google\Chrome\Application\chrome.exe";
            }
    
            return lPath;
        }
    

    【讨论】:

      猜你喜欢
      • 2014-07-22
      • 2015-07-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-03-17
      • 1970-01-01
      • 2011-04-24
      • 2013-06-23
      相关资源
      最近更新 更多