zoukankan      html  css  js  c++  java
  • 调用系统默认浏览器,打开网页

    使用Process.Start("http://www")有些系统会无效,所以,这样比较保险

                var url = "https://www.baidu.com";
                if (true)
                {
    var HTTP_KEY = @"SoftwareMicrosoftWindowsShellAssociationsUrlAssociationshttpUserChoice";
    var key = Microsoft.Win32.Registry.CurrentUser.OpenSubKey(HTTP_KEY, false); var progid = key.GetValue("ProgId").ToString(); key = Microsoft.Win32.Registry.ClassesRoot.OpenSubKey($"{progid}\shell\open\command", false); var value = key.GetValue(null); if (value != null) { var path = value.ToString(); if (path.StartsWith(""")) { var exePath = path.Substring(1); var index = exePath.IndexOf("""); exePath = exePath.Substring(0, index); index += 2; var args = path.Substring(index); args = args.Replace("%1", url); System.Diagnostics.Process.Start(exePath, args); return; } } } if (true) { var key = Microsoft.Win32.Registry.ClassesRoot.OpenSubKey("http\shell\open\command", false); var value = key.GetValue(null); if (value != null) { var path = value.ToString(); if (path.StartsWith(""")) { var exePath = path.Substring(1); var index = exePath.IndexOf("""); exePath = exePath.Substring(0, index); index += 2; var args = path.Substring(index); args = args.Replace("%1", url); System.Diagnostics.Process.Start(exePath, args); return; } } } if (true) { System.Diagnostics.Process.Start(@"C:Program FilesInternet ExplorerIEXPLORE.EXE", url); }
  • 相关阅读:
    HDU 1849 Rabbit and Grass
    HDU 1848 Fibonacci again and again
    HDU 1847 Good Luck in CET-4 Everybody!
    HDU 1846 Brave Game
    HDU 1387 Team Queue
    HDU 1870 愚人节的礼物
    HDU 1509 Windows Message Queue
    HDU 4381 Grid
    HDU 5800 To My Girlfriend
    HDU 5806 NanoApe Loves Sequence Ⅱ
  • 原文地址:https://www.cnblogs.com/IWings/p/14659407.html
Copyright © 2011-2022 走看看