0

Let's say the user has an opened explorer window with the folder W:\abc opened on it.

I have two questions:

  1. Can I know if the folder W:\abc is currently opened?
  2. Can I change the path of the currently opened folder? For example make it W:\?
user990635
  • 3,979
  • 13
  • 45
  • 66

4 Answers4

0

I do not think this is possible. I don't know of a way of interacting with a running Explorer process in this way.

Paul J
  • 476
  • 2
  • 8
0

To answer your first question, it depends on your OS version, but I have used the Shell Document Viewer to get a list of all of the currently open shell windows on my system in the past. You can then filter the shellWindows list accordingly.

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

string fileName;

foreach ( SHDocVw.InternetExplorer ie in shellWindows )
{
    fileName = Path.GetFileNameWithoutExtension( ie.FullName ).ToLower();

    if ( fileName( "explorer" ) )
        Console.WriteLine( "Explorer looking at : {0}", ie.LocationURL );
}

An alternative is to get a list of all of the running processes, filter for explorer.exe and you could get the currently opened path using Process.MainWindowTitle like this:

var processList = Process.GetProcesses();

foreach (Process process in processList)
{
    // do something here with process.MainWindowTitle
}
Dutts
  • 5,781
  • 3
  • 39
  • 61
0

You can do this, but you need to use a lot of calls to native code. Raymond Chen has an example of how to do this with direct WinAPI calls in C:

Querying information from an Explorer window

I've not fully evaluated the code, but I'm pretty confident it could be converted to C#. You'll need a significant amount of knowledge of P/Invoke and C to do so though.

pixelbadger
  • 1,556
  • 9
  • 24
0

1) You can enumerate all opened instances of Explorer and compare your folder with current folder of every instance of Explorer. Sample of enumeration.

2) You can call BrowseObject method of IShellBrowser object to navigate to new folder. Sample:

procedure BrowseToFolder(AShellBrowser: IShellBrowser; const AFolder: UnicodeString);
var
  DesktopFolder: IShellFolder;
  Eaten: DWORD;
  IDList: PItemIDList;
  Attr: DWORD;
begin
  SHGetDesktopFolder(DesktopFolder);
  try
    Attr := 0;
    OleCheck(DesktopFolder.ParseDisplayName(0, nil, PWideChar(AFolder), Eaten, IDList, Attr));
    try
      AShellBrowser.BrowseObject(IDList, SBSP_ABSOLUTE);
    finally
      CoTaskMemFree(IDList);
    end;
  finally
    DesktopFolder := nil;
  end;
end;
Community
  • 1
  • 1
Denis Anisimov
  • 3,297
  • 1
  • 10
  • 18