George2
George2

Reputation: 45801

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

Upvotes: 1

Views: 5604

Answers (3)

Anirudh Goel
Anirudh Goel

Reputation: 4721

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 = "

Upvotes: 2

user36457
user36457

Reputation:

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

Upvotes: 2

Christian C. Salvadó
Christian C. Salvadó

Reputation: 828002

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);

Upvotes: 3

Related Questions