zoukankan      html  css  js  c++  java
  • Code: Open URL by a New Browser

    C#

    private void OpenUrl(string url)
    {
        
    string browser = GetDefaultBrowser();
        
    if ( browser.Length > 0 )
        
    {
            ProcessStartInfo psi 
    = new ProcessStartInfo();
            psi.UseShellExecute 
    = false;
            psi.Arguments
    = url;
            psi.FileName
    = browser;
            System.Diagnostics.Process.Start(psi);
        }

        
    else
        
    {
            System.Diagnostics.Process.Start(url);
        }

    }


    private string GetDefaultBrowser()
    {
        
    string browser = String.Empty;
        RegistryKey key 
    = null;
        
    try
        
    {
            key 
    = Registry.ClassesRoot.OpenSubKey(@"HTTP\shell\open\command"false);
            browser 
    = key.GetValue(null).ToString().ToLower().Replace("\"""");
            if !browser.EndsWith(".exe") )
            
    {
                browser 
    = browser.Substring(0, browser.LastIndexOf(".exe") + 4);
            }

        }

        
    catch
        
    {
            
    if ( key != null )
            
    {
                key.Close();
            }

        }

       
    return browser;
    }


    VB.NET

    Private Sub OpenUrl() Sub OpenUrl( ByRef url As String )
       
    Dim browser As String = GetDefaultBrowser()
        
    If browser.Length > 0 Then
           
    Dim psi As ProcessStartInfo = New ProcessStartInfo
            psi.UseShellExecute 
    = False
            psi.Arguments
    = url
            psi.FileName 
    = browser
            System.Diagnostics.Process.Start(psi)
        
    Else
            System.Diagnostics.Process.Start(url)
        
    End If
    End Sub


    Private Function GetDefaultBrowser()Function GetDefaultBrowser()
        
    Dim browser As String = String.Empty
        
    Dim key As RegistryKey
        
    Try
            key 
    = Registry.ClassesRoot.OpenSubKey("HTTP\shell\open\command"False)
            browser 
    = key.GetValue(Nothing).ToString().ToLower().Replace("""""")
            
    If Not browser.EndsWith(".exe"Then
                browser 
    = browser.Substring(0, browser.LastIndexOf(".exe"+ 4)
            
    End If
        
    Catch ex As Exception
            
    If Not key Is Nothing Then
                key.Close()
            
    End If
        
    End Try
        GetDefaultBrowser 
    = browser
    End Function

    traceBack:  http://www.cnblogs.com/birdshome/archive/2005/09/11/NewBrowser.html

  • 相关阅读:
    双11专刊|云原生数据仓库AnalyticDB支撑双11,大幅提升分析实时性和用户体验
    LeetCode_Binary Tree Inorder Traversal
    LeetCode_4Sum
    LeetCode_Add Binary
    LeetCode_Add Two Numbers
    LeetCode_3Sum Closest
    Building CEGUI with Ogre 1.8.1
    LeetCode_3Sum
    LeetCode_Climbing Stairs
    LeetCode_Binary Tree Level Order Traversal
  • 原文地址:https://www.cnblogs.com/hdjjun/p/1223880.html
Copyright © 2011-2022 走看看