Вопрос

I am trying to launch Google Chrome browser from a .NET program, with arguments. But I get strange behavior.

The following launches Chrome in 'incognito' mode from a command line. It works fine.

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

But the following does not work in .NET. Chrome does open, but not incognito and it goes to this weird 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
Это было полезно?

Решение

You can use shortcut when call the chrome.exe instead using full path location.

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

More: start-google-chrome-from-run-windows-key-r

UPDATE

I found what is your problem in your code. Your code using –-incognito in the parameter, but it should be --incognito.

See the first character in that parameter. Should be - instead .

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

Другие советы

You can also read the chrome path from the registry:

    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;
    }
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top