none
Passing arguments to explorer.exe

    Question

  • After searching the web for a while I still have come up with nothing even remotely helpful for what I'm trying to accomplish, although it is a fairly odd concept. What I'm looking to do is loop through all the current open windows (I know there is a function for that this isn't the part I need help with) and locate the currently open windows file/folder explorer window. Should this window be found I want to be able change the folder path of that window. For example if it is currently viewing the users desktop I would like to change it to the users "my documents" directory. What I've found in my searching that hadn't ever occurred to me before is that explorer.exe is the host process for most of windows and that any window for file/folder exploring is contained in this process. So that has lead me to the conclusion that I need to send a command to that process. I'm sure there's a way to do this because some of windows functions such as find target do this same thing. 

     

    Cliffs :

    Looking to send a command/argument to the running explorer.exe that will change the directory path of a open windows explorer window.

    Not looking for Process.Start("explorer.exe","arguments here")

    Monday, January 02, 2012 4:17 PM

Answers

  • So if I understand correctly you want to find all Windows Explorer windows that are open (not just the processes since Explorer is also the Windows shell) and change the folder they are currently viewing to something else.  Note that there can be any # of these windows open at once and they might or might not be related to the same process.

    There is no API available that will allow you to change the currently viewed folder in Explorer.  I'm not even sure this makes sense security-wise.  A hacker could really do some damage if they could control all the Explorer windows.  Can you provide a more clear justification as to why you'd want to do this?  I can think of some ways via the COM interface but the trick would be getting the COM interface instance for an arbitrary window which I'm not sure can be done. 

    Michael Taylor - 1/2/2012
    http://msmvps.com/blogs/p3net

    Monday, January 02, 2012 4:53 PM
  • I see what you're talking about now.  Please be aware that this is not actually secure in any way.  What is really going on is that Windows identifies several directories specially (like CP).  To make things more manageable the names aren't hard coded but some GUID is (the CLSID as it is generally referenced).  So Windows sees a folder with the .{GUID} syntax and it can do special things.  This is the basics of how virtual shell folders work.

    Nevertheless I don't see how this is solving your problem.  It doesn't control visibility in Explorer.  Also note that the article you referenced actually had to be run explicitly by the user, it wasn't an automatic process. 

    Your last statement says you want to prevent a large # of windows from appearing when navigating through a directory.  Is this something you're doing (in your program you're writing) or is this something that Windows is doing automatically?  By default it won't do that.  You have to set an option in Explorer before it'll open each folder in its own window.

    Michael Taylor - 1/3/2012
    http://msmvps.com/blogs/p3net

    Tuesday, January 03, 2012 2:55 PM

All replies

  • So if I understand correctly you want to find all Windows Explorer windows that are open (not just the processes since Explorer is also the Windows shell) and change the folder they are currently viewing to something else.  Note that there can be any # of these windows open at once and they might or might not be related to the same process.

    There is no API available that will allow you to change the currently viewed folder in Explorer.  I'm not even sure this makes sense security-wise.  A hacker could really do some damage if they could control all the Explorer windows.  Can you provide a more clear justification as to why you'd want to do this?  I can think of some ways via the COM interface but the trick would be getting the COM interface instance for an arbitrary window which I'm not sure can be done. 

    Michael Taylor - 1/2/2012
    http://msmvps.com/blogs/p3net

    Monday, January 02, 2012 4:53 PM
  • That's exactly correct. Justification wise here's what I'm attempting to do....

     

    As I'm sure you're aware window has a built in way of "locking" folders by adding a certain extension(s) to them. The program I am writing changes the shell registry value for folder opening to the path of my application. In this way my application handles all folder opening. The purpose of this is to extend the folder locking functionality. However in this way whenever my application is open if the folder is not already locked I would like to just open that folder in the default windows explorer etc. It's very easy to just start a new explorer process with the arguments however, if a user has a explorer window open and is opening folders via that window every time a folder that wasn't locked is open a brand new window would appear, this is why I'm looking to be able to just change the path of that window. 

     

    I hope that makes sense, I'm aware that it's a very odd request but I'm trying to write a proof of concept type application for my comp sci class and I think that something like this would be very unique and a cool thing to extend upon. 

    Monday, January 02, 2012 9:03 PM
  • This has all the sounds of a virus to me.  In fact there are already viruses that do just that - taking over folder verbs.  I'm not aware of any Explorer functionality that allows locking of any folder.  Can you elaborate?  The NTFS permissions determine what a user can and cannot do.

    As for the remainder of your explanation I don't completely follow what you're trying to do.  What I could understand I don't think is possible.  Explorer doesn't prevent you from navigating to any folder (ignoring NTFS).  The only thing you have some control over is the root that Explorer displays but even that is limited.  Nonetheless all the functionality would require that you write an Explorer extension because you're wanting to circumvent the navigation in Explorer and only a shell extension even remotely stands a chance in doing that. 

    Now if you are refering to the fact that Explorer can show things like Control Panel and Network which are "locked" in their content then it is an entirely different matter.  In fact these aren't real folders but virtual directories.  Shell extensions can create "directories" in Explorer that are completely managed in code.  The extension works with Explorer to show the virtual items and/or the extension can show its own view.  For example early shell extensions added the registry to Windows Explorer.  All this functionality is documented in the various MSDN documentation on how to write Shell Extensions.

    Michael Taylor - 1/2/2012
    http://msmvps.com/blogs/p3net

    Tuesday, January 03, 2012 4:15 AM
  • This is the "locking" that I'm referring to 

     

    http://www.codeproject.com/KB/files/Unique_Folder_Protection.aspx

     

    The only real reason I need to live change the directory after making my program handle folder opening is to prevent a large number of windows from appearing when navigating through a directory and sub directory.

    Tuesday, January 03, 2012 6:18 AM
  • I see what you're talking about now.  Please be aware that this is not actually secure in any way.  What is really going on is that Windows identifies several directories specially (like CP).  To make things more manageable the names aren't hard coded but some GUID is (the CLSID as it is generally referenced).  So Windows sees a folder with the .{GUID} syntax and it can do special things.  This is the basics of how virtual shell folders work.

    Nevertheless I don't see how this is solving your problem.  It doesn't control visibility in Explorer.  Also note that the article you referenced actually had to be run explicitly by the user, it wasn't an automatic process. 

    Your last statement says you want to prevent a large # of windows from appearing when navigating through a directory.  Is this something you're doing (in your program you're writing) or is this something that Windows is doing automatically?  By default it won't do that.  You have to set an option in Explorer before it'll open each folder in its own window.

    Michael Taylor - 1/3/2012
    http://msmvps.com/blogs/p3net

    Tuesday, January 03, 2012 2:55 PM