如何调用IE打开本地html文件?

时间:2009-07-13 05:37:33

标签: c# .net internet-explorer

我使用的是VSTS 2008 + C#+ .Net 2.0。我想调用IE来打开位于我当前可执行文件的页面子文件夹下的html文件。

由于我的程序可以在Windows Vista下运行,我想在管理权限下运行IE(以管理员身份运行)。

要参考的任何代码?我对如何编写可在Windows Vista和Windows XP上运行的可移植代码特别感兴趣(我认为Windows XP没有像管理员一样运行的功能)

编辑1:

我正在使用以下代码,但没有打开UAC(用户访问控制)提示消息框,让我选择继续以管理员身份运行。有什么想法是错的吗?

    ProcessStartInfo startInfo = new ProcessStartInfo("IExplore.exe");
    startInfo.Verb = "RunAs";
    startInfo.Arguments = @"C:\test\default.html";
    Process.Start(startInfo);
提前谢谢, 乔治

3 个答案:

答案 0 :(得分:3)

要处理相对路径,请查看GetFullPath method

string fullPath = Path.Combine(Path.GetFullPath(@".\dir\dir2"), "file.html");
System.Diagnostics.Process.Start("iexplore.exe", fullPath);

答案 1 :(得分:2)

System.Diagnostics.Process.Start("iexplore.exe", @"C:\mypage.html");

答案 2 :(得分:2)

using System.Diagnostics;

Process the_process = new Process();
the_process.StartInfo.FileName = "iexplore.exe";
the_process.StartInfo.Verb = "runas";
the_process.StartInfo.Arguments = "myfile.html";
the_process.Start();

动词“runas”将提示UAC并在管理权限下运行。

你可以在vista和XP下运行该代码。它会产生同样的效果。 至于你要打开的文件, 你可以使用它将它作为参数传递给iexplore.exe the_process.arguments =“

相关问题