简体   繁体   中英

how to invoke IE to open a local html file?

I am using VSTS 2008 + C# + .Net 2.0. And I want to invoke IE to open an html file located under pages sub-folder of my current executable.

Since my program may run under Windows Vista, I want to invoke IE under administrative permissions (Run As Administrator).

Any code to make reference? I am especially interested in how to write portable code, which works on both Windows Vista and Windows XP (I think Windows XP does not have function like Run As Administrator)

EDIT 1:

I am using the following code, but there is no UAC (User Access Control) prompt message box opened up to let me select Continue to run with Administrator. Any ideas what is wrong?

    ProcessStartInfo startInfo = new ProcessStartInfo("IExplore.exe");
    startInfo.Verb = "RunAs";
    startInfo.Arguments = @"C:\test\default.html";
    Process.Start(startInfo);

thanks in advance, Geroge

For working with relative paths, give a look to the GetFullPath method .

string fullPath = Path.Combine(Path.GetFullPath(@".\dir\dir2"), "file.html");
System.Diagnostics.Process.Start("iexplore.exe", fullPath);
System.Diagnostics.Process.Start("iexplore.exe", @"C:\mypage.html");
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();

the verb "runas" will make it prompt the UAC And run under administrative priviliges.

you can run that code underboth vista and XP. It will yield same effect. As for the file which you want to open, you can pass it as the argument to iexplore.exe by using the_process.arguments = "

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM