【问题标题】:Win32Exception when using Process.Start()使用 Process.Start() 时出现 Win32Exception
【发布时间】:2019-11-19 07:59:56
【问题描述】:

如何使用 c# 打开谷歌浏览器?

显示System.ComponentModel.Win32Exception: '系统找不到指定的文件'

我也试过Process.Start("C:\\Program Files(x86)\\Google\\Chrome\\Application\\chrome.exe");,但它显示相同的异常

using System;

using System.Diagnostics;

namespace tempTest
{
    class Program
    {
        static void Main(string[] args)
        {
            Process.Start("chrome.exe");
        }
    }
}

【问题讨论】:

标签: c#


【解决方案1】:

可以从注册表中读取 chrome 应用程序路径。 您可以尝试以下代码:

            var key = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\chrome.exe", false);

            if(key != null)
            {
                var path = Path.Combine(key.GetValue("Path").ToString(), "chrome.exe");

                if(File.Exists(path))
                {
                    Process.Start(path);
                }
            }

【讨论】:

  • Chrome 在 HKLM 中不是必需的。它可以在 HKCU 中,因为它可以为单个用户而不是所有用户安装
  • @Cid,你是对的,但我认为我们应该尝试读取两个基本密钥位置以获得正确的 chrome 安装路径。
  • 是的,当然。希望这是同一个键:HKCU\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\chrome.exe
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2019-10-03
  • 2021-08-06
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多