private void button2_Click(object sender, EventArgs e)
        {
            try
            {
                string app = "chrome.exe";
                RegistryKey regKey = Registry.LocalMachine;
                RegistryKey regSubKey = regKey.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\" + app, false);
                string strKey = string.Empty;
                object objResult = regSubKey.GetValue(strKey);
                RegistryValueKind regValueKind = regSubKey.GetValueKind(strKey);
                if (regValueKind == Microsoft.Win32.RegistryValueKind.String)
                {
                    this.tb_path.Text = objResult.ToString();
                }
            }
            catch
            {
                this.tb_path.Text = "未获取到路径,可能是没有安装chrome浏览器!";
            }
        }

如果电脑上安装了chrome,那么就会把路径显示在文本框中,如果没有安装,那么代码运行到   object objResult = regSubKey.GetValue(strKey);  就会报错,进入catch。

相关文章:

  • 2022-12-23
  • 2022-02-15
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-09-03
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-12-05
  • 2022-01-27
  • 2021-11-03
  • 2021-09-04
相关资源
相似解决方案