I want to control the state of a File Explorer window programmatically (using Matlab). Specifically, I would like to change the window state (minimized, maximized, pop to foreground), change the folder that is currently viewed, and maybe preselect a file.
I know that I can open File Explorer through system
calls, but I don't want to open a new window every time. I am also aware of the limited control that DDE offers. But DDE is horribly outdated, even worse documented, and Matlab has better support for COM and .NET interfaces than for DDE.
Does the File Explorer expose COM or .NET interfaces? If so, where can I find out about them? Especially knowing the PROGID of File Explorer would help a lot.
I searched online, but COM and .NET are not easily searchable - not even on the Windows Developer search (the top results are all domains ending in .com and .net ...)
Update:
Thanks to the information given so far, I was able to start a new Explorer Window using
h_s = actxserver('shell.application');
h_s.Explore('c:\Users')
But I fail to see how this would allow me to manipulate the Explorer window. As far as I understand the documentation, the shell.application object allows me to interact with the shell, not with File Explorer. I did not find a method that allows me to change the selected file. Also, everytime I call h.Explore()
, a new window is opened.
As an alternative, by poking around the registry (I looked for keys in HKEY_CLASSES_ROOT that have "sub-keys" called CLSID) I found the progID of Internet Explorer, but navigating to a file URI does not work. Instead I windows opens an Internet Explorer window and a new File Explorer window that shows the wrong location.
h_e = actxserver('InternetExplorer.Application')
h_e.Navigate('file:///C:/Users')
Almost two years later, I had quite a similar (if less ambitious) goal: from Matlab, I wanted to record the current paths in all the File Explorer windows. The code below works for me (and perhaps can be extended to do additional manipulations):
explorer = actxserver('Shell.Application');
windows = explorer.Windows;
nWins = windows.Count;
for iWin = 1:nWins
w1 = windows.Item(int32(iWin-1)); % Item is zero-based
URL = w1.get('LocationURL'); % https://msdn.microsoft.com/en-us/library/aa752127%28v=vs.85%29.aspx
if isequal(lower(URL(1:5)), 'file:') % File Explorer window
if isequal(URL(6:8), '///') % Local file
pn = URL(9:end);
else
pn = URL(6:end); % Remote file
end
pn = strrep(pn, '/', '\'); % I'm a Windows guy
pn = strrep(pn, '%20', ' '); % ...and a WYSIWYG guy
elseif isequal(lower(URL(1:5)), 'http:')
pn = URL; % Internet Explorer Window
end
disp(pn)
end