C# 如何打开默认浏览器主页
比如我的默认浏览器是360,主页未知,我要的就是点击按钮就能够打开浏览
[DllImport("shell32.dll")]
public static extern IntPtr ShellExecute(
IntPtr hwnd,
string lpOperation,
string lpFile,
string lpParameters,
string lpDirectory,
int a);
我用的是这个API,不填URL不行,有没有什么办法可以不用指定URL而打开默认浏览器?
追问:这是调用IE浏览器,打开的是IE,不是默认浏览器。打开的是一个主页啊,不是两个,是不是你设置了两个主页啊?我要的是打开默认浏览器,不过那个浏览器是否用到IE内核,不过是360还是火狐等
答案:1.引用
2.代码
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using SHDocVw;
namespace IE
{
public partial class FrmMain : Form
{
public FrmMain()
{
InitializeComponent();
}
private void btnOpen_Click(object sender, EventArgs e)
{
InternetExplorer IE = new InternetExplorer();
IE.Visible = true;//显示浏览器(必须的)
IE.GoHome();//打开主页(比如打开的是360浏览器,会打开两页(都是主页)。如果屏蔽这句,也是打开两页,第二页是空页)
}
}
}
调用 IE:
System.Diagnostics.Process myProcess = new System.Diagnostics.Process();
myProcess.StartInfo.FileName = "iexplore.exe";
myProcess.StartInfo.Arguments = " http://www.net0and1.com/";
myProcess.Start();
调用默认浏览器:
string target= " http://www.net0and1.com";
//Use no more than one assignment when you test this code.
//string target = " ftp://ftp.microsoft.com";
//string target = "C:\\Program Files\\Microsoft Visual Studio\\INSTALL.HTM";
try
{
System.Diagnostics.Process.Start(target);
}
catch
(
System.ComponentModel.Win32Exception noBrowser)
{
if (noBrowser.ErrorCode==-2147467259)
MessageBox.Show(noBrowser.Message);
}
catch (System.Exception other)
{
MessageBox.Show(other.Message);
}设置里面
上一个:C# 操作XML信息的问题
下一个:C#中如何判断TreeView选中