using JSMachine.DCS.Infrastructure; using Microsoft.Win32; using System; using System.Collections.Generic; using System.Diagnostics; using System.Linq; using System.Text; using System.Threading.Tasks; namespace JSMachine.WMS.Infrastructure.Helper { public static class ProcessHelper { //调用浏览器打开指定的网址 public static bool OpenBrowserUrl(string url) { try { //优先用IE,不行再尝试用谷歌 if (OpenIe(url)) return true; // 64位注册表路径 string openKey = @"SOFTWARE\Wow6432Node\Google\Chrome"; if (IntPtr.Size == 4) { // 32位注册表路径 openKey = @"SOFTWARE\Google\Chrome"; } RegistryKey appPath = Registry.LocalMachine.OpenSubKey(openKey); // 谷歌浏览器就用谷歌打开,没找到就用系统默认的浏览器 // 谷歌卸载了,注册表还没有清空,程序会返回一个"系统找不到指定的文件。"的bug if (appPath != null) { Process result = Process.Start("chrome.exe", url); return result != null; } else { Process result = Process.Start("chrome.exe", url); return result != null; } } catch (Exception ex) { LogHelper.Error(ex.Message); } return false; } /// /// 用IE打开浏览器 /// /// public static bool OpenIe(string url) { Process process = new(); process.StartInfo.FileName = "iexplore.exe"; //IE浏览器,可以更换 process.StartInfo.Arguments = url; try { process.Start(); return true; } catch (Exception ex) { LogHelper.Error($"使用IE打开网址错误:{ex.Message}"); } return false; } } }