views:

115

answers:

3

How to get a fully qualified path to MS Explorer in .NET?

The path will be used to launch a new instance of MS Explorer with some command line parameters.

+1  A: 

Windows Explorer is always in the Path, so just calling explorer.exe with the command line parameters should be enough.

Same applies to Internet Explorer, whose file name is iexplore.exe.

devio
A: 

As said by @devio, you don't really need to specify it as it's in the path, but for the sake of completeness, you could use the Environment.ExpandEnvironmentVariables method:

string path = Environment.ExpandEnvironmentVariables(@"%SystemRoot%\Explorer.exe");
Jon Grant
A: 

Thanks!

The full code snippet for anyone interested, is:

    // Launch MS Explorer with the correct log file selected.

    //string pathToExplorer = System.IO.Path.Combine( Environment.ExpandEnvironmentVariables("%WinDir%"),
    //                                                "explorer.exe");

    string pathToExplorer = "explorer.exe";

    string pathToLogFile = Process.GetCurrentProcess().MainModule.FileName + ".log";

    string arguments = String.Format(   CultureInfo.InvariantCulture,
                                        "/select, \"{0}\"",
                                        pathToLogFile);

    // C:\Windows\explorer.exe /select, "C:\projects\trunk\bin\MyCompany.App.StackTester.exe.log"

    Process.Start(  pathToExplorer,
                    arguments);
Thomas Bratt