I’m looking for a way to close a Windows explorer window that’s open to a certain folder. Say c:\users\bob\folder. I can close all explorers with the code below, but this is obviously not what I want to do. Is this possible?
foreach (Process p in Process.GetProcessesByName("explorer"))
{
p.Kill();
}
Thanks
This article that got me most of the way there: http://omegacoder.com/?p=63
I found a way using a COM library called “Microsoft Internet Controls” that looks more intended for Internet Explorer, but I gave up trying to use the process ID’s and
MainWindowTitlestuff since explorer.exe only uses one process for all open windows and I couldn’t pin down how to get the window title text or file system location from that.So first, add a reference to Microsoft Internet Controls from the COM tab, then:
This little routine did the trick for me:
One caveat, and probably owing to the fact this library is geared toward IE, is you have to use forward slashes in your folder path… That’s because the true
LocationURLthat comes back from theieobject is in the formfile:///C:/Users/...