Open windows Explorer on Windows 11

51 Views Asked by At

I am using c# on windows 11 i am trying below code to to open the windows explorer on windows 11, The Windows explorer open and close directly, when i check the task manager i found Windows explorer already run but not display on the desktop, the windows ecplorer opening briefly and then closing without displaying the window, yet still remaining active in the task manager

my code :

var myFile = "C:\\Windows\\explorer.exe";
var workingFolder = "C:\\Windows";
var process = new System.Diagnostics.ProcessStartInfo();
process.FileName = myFile;
process.WorkingDirectory = workingFolder;
process.UseShellExecute = false;
process.Arguments = "d:\\";
System.Diagnostics.Process.Start(process);
1

There are 1 best solutions below

0
Matthew Watson On

You shouldn't try to run "Explorer.exe" directly. For starters, you don't know if it is actually in "C:\Windows".

Instead, specify that you want to use the shell to open "D:\" like so:

System.Diagnostics.Process.Start(
    new System.Diagnostics.ProcessStartInfo {
        FileName        = "D:\\",
        UseShellExecute = true,
        Verb            = "open" });