打开默认的Web浏览器 [英] Opening default web browser
本文介绍了打开默认的Web浏览器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我使用了以下功能打开用户的默认Web浏览器。
I am using the function below to open the user's default web browser.
Public Function ShowHelp(ByVal url As String) As System.Diagnostics.Process
Dim startInfo As New Diagnostics.ProcessStartInfo()
startInfo.FileName = url
startInfo.WindowStyle = ProcessWindowStyle.Maximized
Return System.Diagnostics.Process.Start(startInfo)
End Function
有几次该函数返回的错误(对用户机)的系统找不到指定文件的
我猜的用户没有设置默认的Web浏览器。 为什么我得到这个错误?我怎么能调用此函数之前添加默认的Web浏览器检查?
I guess the user has not set a default web browser. Why i get this error? How could i add a default web browser check before calling this function?
推荐答案
这是在C#中,但是这是一个很好的文章:
This is in C#, but this is a good article:
http://ryanfarley.com/blog/archive/2004/ 5月16日/ 649.aspx
下面是C#作为VB.NET:
Here's the C# as VB.NET:
Private Function getDefaultBrowser() As String
Dim browser As String = String.Empty
Dim key As RegistryKey = Nothing
Try
key = Registry.ClassesRoot.OpenSubKey("HTTP\shell\open\command", False)
'trim off quotes
browser = key.GetValue(Nothing).ToString().ToLower().Replace("""", "")
If Not browser.EndsWith("exe") Then
'get rid of everything after the ".exe"
browser = browser.Substring(0, browser.LastIndexOf(".exe") + 4)
End If
Finally
If key IsNot Nothing Then
key.Close()
End If
End Try
Return browser
End Function
这篇关于打开默认的Web浏览器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文