| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125 |
- using Microsoft.Win32;
- using System.Diagnostics;
- namespace Client.Utils
- {
- public class BrowserHelper
- {
- private static void OpenChrometBrowser(string url)
- {
- try
- {
- var openKey = @"SOFTWARE\Wow6432Node\Google\Chrome";
- if (IntPtr.Size == 4)
- {
- openKey = @"SOFTWARE\Google\Chrome";
- }
- RegistryKey appPath = Registry.LocalMachine.OpenSubKey(openKey);
- if (appPath != null)
- {
- var result = Process.Start("chrome.exe", url);
- if (result == null)
- {
- OpenIetBrowser(url);
- }
- }
- else
- {
- OpenDefaultBrowser(url);
- }
- }
- catch
- {
- OpenDefaultBrowser(url);
- }
- }
- private static void OpenIetBrowser(string url)
- {
- try
- {
- Process.Start("iexplore.exe", url);
- }
- catch (Exception ex)
- {
- MessageBox.Show(ex.Message);
- try
- {
- if (File.Exists(@"C:\Program Files\Internet Explorer\iexplore.exe"))
- {
- ProcessStartInfo processStartInfo = new ProcessStartInfo
- {
- FileName = @"C:\Program Files\Internet Explorer\iexplore.exe",
- Arguments = url,
- UseShellExecute = false,
- CreateNoWindow = true
- };
- Process.Start(processStartInfo);
- }
- else
- {
- if (File.Exists(@"C:\Program Files (x86)\Internet Explorer\iexplore.exe"))
- {
- ProcessStartInfo processStartInfo = new ProcessStartInfo
- {
- FileName = @"C:\Program Files (x86)\Internet Explorer\iexplore.exe",
- Arguments = url,
- UseShellExecute = false,
- CreateNoWindow = true
- };
- Process.Start(processStartInfo);
- }
- else
- {
- if (MessageBox.Show("Internet Explorer is not installed in the system. Do you want to download and install it?", null, MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question) == DialogResult.Yes)
- {
- OpenDefaultBrowser("http://windows.microsoft.com/zh-cn/internet-explorer/download-ie");
- }
- }
- }
- }
- catch (Exception exception)
- {
- MessageBox.Show(exception.Message);
- }
- }
- }
- public static void OpenDefaultBrowser(string url)
- {
- try
- {
- RegistryKey key = Registry.ClassesRoot.OpenSubKey(@"http\shell\open\command\");
- if (key != null)
- {
- string s = key.GetValue("").ToString();
- var lastIndex = s.IndexOf(".exe", StringComparison.Ordinal);
- var path = s.Substring(1, lastIndex + 3);
- var result = Process.Start(path, url);
- if (result == null)
- {
- var result1 = Process.Start("explorer.exe", url);
- if (result1 == null)
- {
- Process.Start(url);
- }
- }
- }
- else
- {
- var result1 = Process.Start("explorer.exe", url);
- if (result1 == null)
- {
- Process.Start(url);
- }
- }
- }
- catch
- {
- OpenIetBrowser(url);
- }
- }
- }
- }
|