Get the process handler in Windows Explorer

I want to get the handle of my Windows Explorer, not Internet Explorer.

It usually works with

var processes = Process.GetProcesses();
foreach (var process in processes)
{
    var handle = process.Handle;
}

What I want to do is follow these steps:

Bring a specific explorer window to ForeGround. I implemented the ToForeGround method and works great for all other Windows except Windows Explorer

But with Windows Explorer, I get only the process in the taskbar, no matter how many windows are open, there is only one Windows Explorer process.

Or can someone explain to me why Windows Explorer is different from other programs?

+4
source share
3 answers

, , - ShellWindows . Windows Explorer ( Internet Explorer, , "explorer" if, "iexplore" ).

Shell32.dll, Windows/system32

        SHDocVw.ShellWindows shellWindows = new SHDocVw.ShellWindows();

        string filename;
        ArrayList windows = new ArrayList();

        foreach (SHDocVw.InternetExplorer ie in shellWindows)
        {
            filename = Path.GetFileNameWithoutExtension(ie.FullName).ToLower();
            if (filename.Equals("explorer"))
            {
                //do something with the handle here
                MessageBox.Show(ie.HWND.ToString()); 
            }
        }
+4

- , " Windows" ?

shell. Explorer.exe ( ) Windows, , - .

(sort-of) , .

, :

Process.Start(@"C:\SomeFolder\");
+3

The following code iterates through all Explorer and Internet Explorer windows (tabs) (W7 / IE11). The location URL will give the folder that is being viewed in Explorer. If the folder is the one that you need to bring to the fore, you can use HWNDthe window for this and move it to the fore.

Note. The location URL for the Explorer window for Computer will be blank. I am not sure if there are such special cases.

SHDocVw.ShellWindows shellWindows = new SHDocVw.ShellWindows();

foreach (SHDocVw.InternetExplorer window in shellWindows){
    if (window.LocationURL.Contains("Some Folder I am interested in")){
        SetForegroundWindow((IntPtr)window.HWND);
    }
}
+3
source

Source: https://habr.com/ru/post/1570550/


All Articles