Code: Open URL by a New Browser

简介:

C#

None.gif private  void OpenUrl( string url)
ExpandedBlockStart.gif ContractedBlock.gif dot.gif{
InBlock.gif     string browser = GetDefaultBrowser();
InBlock.gif     if ( browser.Length > 0 )
ExpandedSubBlockStart.gif ContractedSubBlock.gif     dot.gif{
InBlock.gif        ProcessStartInfo psi = new ProcessStartInfo();
InBlock.gif        psi.UseShellExecute =  false;
InBlock.gif        psi.Arguments = url;
InBlock.gif        psi.FileName = browser;
InBlock.gif        System.Diagnostics.Process.Start(psi);
ExpandedSubBlockEnd.gif    }
InBlock.gif     else
ExpandedSubBlockStart.gif ContractedSubBlock.gif     dot.gif{
InBlock.gif        System.Diagnostics.Process.Start(url);
ExpandedSubBlockEnd.gif    }
ExpandedBlockEnd.gif}
None.gif
None.gif private string GetDefaultBrowser()
ExpandedBlockStart.gif ContractedBlock.gif dot.gif{
InBlock.gif     string browser = String.Empty;
InBlock.gif    RegistryKey key =  null;
InBlock.gif     try
ExpandedSubBlockStart.gif ContractedSubBlock.gif     dot.gif{
InBlock.gif        key = Registry.ClassesRoot.OpenSubKey(@"HTTP\shell\open\command",  false);
InBlock.gif        browser = key.GetValue( null).ToString().ToLower().Replace("\"", "");
InBlock.gif         if ( !browser.EndsWith(".exe") )
ExpandedSubBlockStart.gif ContractedSubBlock.gif         dot.gif{
InBlock.gif            browser = browser.Substring(0, browser.LastIndexOf(".exe") + 4);
ExpandedSubBlockEnd.gif        }
ExpandedSubBlockEnd.gif    }
InBlock.gif     catch
ExpandedSubBlockStart.gif ContractedSubBlock.gif     dot.gif{
InBlock.gif         if ( key !=  null )
ExpandedSubBlockStart.gif ContractedSubBlock.gif         dot.gif{
InBlock.gif            key.Close();
ExpandedSubBlockEnd.gif        }
ExpandedSubBlockEnd.gif    }
InBlock.gif    return browser;
ExpandedBlockEnd.gif}


VB.NET

ExpandedBlockStart.gif ContractedBlock.gif Private Sub OpenUrl() Sub OpenUrl( ByRef url As String )
InBlock.gif    Dim browser As  String = GetDefaultBrowser()
InBlock.gif     If browser.Length > 0  Then
InBlock.gif        Dim psi  As ProcessStartInfo =  New ProcessStartInfo
InBlock.gif        psi.UseShellExecute =  False
InBlock.gif        psi.Arguments = url
InBlock.gif        psi.FileName = browser
InBlock.gif        System.Diagnostics.Process.Start(psi)
InBlock.gif     Else
InBlock.gif        System.Diagnostics.Process.Start(url)
InBlock.gif     End  If
ExpandedBlockEnd.gif End Sub
None.gif
ExpandedBlockStart.gif ContractedBlock.gif Private  Function GetDefaultBrowser() Function GetDefaultBrowser()
InBlock.gif     Dim browser  As String =  String.Empty
InBlock.gif     Dim key  As RegistryKey
InBlock.gif     Try
InBlock.gif        key = Registry.ClassesRoot.OpenSubKey("HTTP\shell\open\command",  False)
InBlock.gif        browser = key.GetValue( Nothing).ToString().ToLower().Replace("""", "")
InBlock.gif         If  Not browser.EndsWith(".exe")  Then
InBlock.gif            browser = browser.Substring(0, browser.LastIndexOf(".exe") + 4)
InBlock.gif         End  If
InBlock.gif     Catch ex  As Exception
InBlock.gif         If  Not key Is  Nothing Then
InBlock.gif            key.Close()
InBlock.gif         End  If
InBlock.gif     End  Try
InBlock.gif    GetDefaultBrowser = browser
ExpandedBlockEnd.gif End Function

本文转自博客园鸟食轩的博客,原文链接:http://www.cnblogs.com/birdshome/,如需转载请自行联系原博主。

目录
相关文章
POST 请求出现异常!java.io.IOException: Server returned HTTP response code: 400 for URL
POST 请求出现异常!java.io.IOException: Server returned HTTP response code: 400 for URL
1106 0
|
4月前
|
前端开发 Linux Docker
【源码共读】跨平台打开 URL、文件、可执行文件 open
【源码共读】跨平台打开 URL、文件、可执行文件 open
66 1
|
开发工具 git
Gitlab提交代码:You are not allowed to push code to this project.fatal: unable to access requested URL
Gitlab提交代码:You are not allowed to push code to this project.fatal: unable to access requested URL
836 0
Useful code snippet to parse the key value pairs in URL
Useful code snippet to parse the key value pairs in URL
114 0
Useful code snippet to parse the key value pairs in URL
SAP Spartacus里product code出现在url的几种场景
SAP Spartacus里product code出现在url的几种场景
SAP Spartacus里product code出现在url的几种场景
|
Web App开发 Java 网络安全
java.io.IOException: Server returned HTTP response code: 403 for URL: http://start.spring.io
p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px 'Helvetica Neue'; color: #454545} span.s1 {font: 12.0px '.PingFang SC'} 403 Forbidden 是HTTP协议中的一个状态码(Status Code)。
4583 0
|
Java Spring
java.io.IOException: Server returned HTTP response code: 415 for URL:xxxxxx
p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px 'Helvetica Neue'; color: #454545} span.s1 {text-decoration: underline} span.
2380 0
|
数据格式 XML
How to let FIR open a URL when you click an image
When we use FIR as a ad bar, we want FIR can take the visitor to specific web page when visitor click the image.
583 0