limelect 48 Posted April 4, 2020 (edited) I have an application running that uses and depends on explorer (NOT INTERNET EXPLORER). For some reasons once in a while working on my computer explorer closes and I have to open a new one. While this happens I have an explorer open and another one that is unseen.(Hidden). The problem: For my software to work properly I need ONLY ONE open explorer. The solution: To close the unseen explorer. What I tried: OleCheck(CoCreateInstance(CLASS_ShellWindows, nil, CLSCTX_INPROC_SERVER or CLSCTX_LOCAL_SERVER, IShellWindows, ShellWindows)); try for i := ShellWindows.Count - 1 downto 0 do < here shall window.count show 3 (for example). 2 unseen. one open ok. begin Dispatch := ShellWindows.Item(i); if Dispatch<> nil then Down the software, I can see the directory that the explorer shows the directory. The problem : in the loop down to 1 and 0 Dispatch is nil finally, I would like to have all 3 explorer and choose which one to close. P.S if I restart my computer I have 1 explorer open and everything is OK. Thanks for your help. Any piece of software can help. This is the program very useful http://limelect.com/downloads/explorer-list/ Edited April 4, 2020 by limelect Share this post Link to post
limelect 48 Posted April 5, 2020 (edited) Well, it seems that we need a professional group. If you think that I will put a trivial question? Well, it is also very hard to debug under normal computer work. Most of you cannot even make hidden explorer under normal condition or not noticed it. But any suggestion that will bypass ShellWindows will be appreciated. One simple solution is to give the user a message telling him to restart his computer. P.S I do not even know why my computer does it, but it happens during Delphi development especially during this project. (API breakpoint)? Edited April 5, 2020 by limelect Share this post Link to post
Fr0sT.Brutal 900 Posted April 5, 2020 Honestly, I'm not sure I understand your needs but maybe FindWindow or enum processes can help you Share this post Link to post
limelect 48 Posted April 5, 2020 @Fr0sT.Brutal Let me elaborate. Once in awhile Explorer closes. It happened while I develop. I do not know how it happens since it is not a problem affecting computer work. Then, with reopened explorer, I go to a directory as needed. Now you have 2 Explorers. One with the directory needed ANOTHER HIDDEN. How do I know? Since with ShellWindows I count 2. I want to be able to delete the hidden explorer. Looking for process did help. As you understand this is not a common problem and there's NO documentation about such a problem. Before asking for help I tried a huge amount of API variations and programs. However all really on ShellWindows. I could not find any different way to see explorer full information in memory. As for that, I need help. Share this post Link to post
David Heffernan 2345 Posted April 5, 2020 It's common to have lots of explorer processes. There's an option that means each window is run from a different process. I can't understand why you would feel that there should only be a single explorer process. That's for the system to decide. If you want to interact with the system then you need to follow its rules. You don't make the system rules. Share this post Link to post
limelect 48 Posted April 5, 2020 @David Heffernan You are correct but... When you open an explorer it will be first in the list (ShellWindows =0) I made sure I am correct. Now if you open another explorer it will be second (ShellWindows =1) and so on. However in my case, if (ShellWindows =0) is hidden I am in trouble but I fixe it with a message and some process. It will be nice if I could delete (ShellWindows =0) and I hop (ShellWindows =1) will be (ShellWindows =0). Share this post Link to post
limelect 48 Posted April 5, 2020 (edited) What is so crazy about that problem that I came back to check an idea about my software the HIDDEN explorer VANISHED without a computer reset. Now I am back with explorer OK.=1. I have to wait until the problem will reappear. I do not know if fulling around with a process program did it??? crazy Thanks in any case guys. Edited April 5, 2020 by limelect Share this post Link to post
timfrost 78 Posted April 5, 2020 Each Windows process will have a process ID. Can you not track the process ID in order to identify which one you need to interact with? Share this post Link to post
limelect 48 Posted April 5, 2020 (edited) @timfrost No, because process ID does not mean you know to which process name it belongs. If you have a program.exe it has a name and process ID. But a hidden process does not have any name just a number. Or does it, if so what is the name behind explorer. Just an ID does not mean much since you do not know to which program it belongs, very often. especially when the program for some reason is hidden. Do not forget Dispatch := ShellWindows.Item(i); is nil does not give back any known to me information To sum it up I have a program you can download http://limelect.com/downloads/screen-capture/ That cath anything with ID a different kind of screen-capture. Edited April 5, 2020 by limelect Share this post Link to post
David Heffernan 2345 Posted April 5, 2020 I'm afraid that none of this makes a lot of sense. Why do you feel that there should only be one explorer process? Why does that matter? 3 Share this post Link to post
limelect 48 Posted April 5, 2020 @David Heffernan I never said just one there can be many explorer. But my software chooses the first in list. The problem debugging such problematic software that comes and go make me wonder if I am on the right track for solving the hidden explorer that comes and disappears at will. I might be missing something in my software. Maybe you should download my software and see what it dose. There are a lot of people using it and it is quite useful for us. Just unzip and use. No installation. you can always delete. Share this post Link to post
David Heffernan 2345 Posted April 5, 2020 I doubt anyone wants to download your software. I know I don't. Normally if you want help you'd explain more what the problem is. Anyway, never mind. Share this post Link to post
aehimself 396 Posted April 5, 2020 1 hour ago, limelect said: I never said just one there can be many explorer. But my software chooses the first in list. And that is an issue, if you ask me. To be honest I lost track a long time ago, but for a while the Windows Taskbar and the Desktop was hosted by an instance of the same explorer.exe process what you launched when you clicked on "My computer"; maybe Windows is using it for even more undocumented things (like specific background processes; which would answer why they just come and go). If your application requires to interact with an Explorer window, you should let your users to choose which one. But then again - this is how I think. 4 hours ago, limelect said: But a hidden process does not have any name just a number. Wrong. A process has multiple granted properties; like an executable NAME and a PID for example. All processes have that, having visible windows or not, being service applications or not, being launched under a svchost process or not. Depending on how you enumerate those, you get different properties available. I personally never used ShellWindows as I always went for EnumWindows or FindWindow what @Fr0sT.Brutal advised to you already. It's a bit more low level, but opens up tons of opportunities. 2 hours ago, limelect said: Maybe you should download my software and see what it dose. There are a lot of people using it and it is quite useful for us. Just unzip and use. No installation. you can always delete. And this part; I must totally have to agree with @David Heffernan. If someone anonymous on the Internet would tell you "Download my app, it's useful, you always can delete"... would you trust him/her? At this point noone really understands why you are doing what you are doing so they are unable to give you alternatives. Without an understandable code snipplet (e.g. I have no damn clue what "Do not forget Dispatch := ShellWindows.Item(i); is nil" means and I think I'm not alone) or a clear goal set... it just sounds like an other million dollar idea what SW developers are usually getting. 2 Share this post Link to post
limelect 48 Posted April 5, 2020 Well, guys, I give up. I will solve my problems alone. And P.S I started my knowledge a little bit even before Delphi #1. Of which I used quite a lot. And thanks again. Share this post Link to post
Lars Fosdal 1792 Posted April 6, 2020 @limelect What is the nature of the interaction between your app and the file explorer? Would it be better to launch your own explorer with CreateProcessEx? That way, your app would be the owner, and you would know when it closes, and if you need to launch another. In Windows 10, you can control if folder explorer windows should have separate processes by default or not. The default appears to be not, meaning each explorer opened (from f.x. using Win+E) actually is running in the same process. What is your setting? Does changing this setting affect your observable problem? Share this post Link to post
limelect 48 Posted April 6, 2020 (edited) @Lars Fosdal I appreciate your help. But my need is not something can be solved as per your suggestion. I would have done so. First, you can read the description at http://limelect.com/downloads/explorer-list/ Let me explain what it does. The idea to have links by name to directories it is kind of a short cut. It is on the toolbar and when you press a name it opens explorer, ontop, at the directory. ALL MY SOFTWARE comes out of a need. I could not go to a directory by pressing the mouse button a few times. It bugs me. That way I go to a directory at once. As a benefit of this, you have a HISTORY that brings you back to a few days where you worked. I hope this clarifies why is the problem. lastly, if there is an open explorer (=0) I use it otherwise, I open a new one. P.S a few YEARS ago I asked for help to translate c++ to Delphi you remember? it was for this program Edited April 6, 2020 by limelect Share this post Link to post
Lars Fosdal 1792 Posted April 6, 2020 I see. Personally, I rely on the MRU, Quick Access and Libraries functions that are built into the File Explorer. They are sufficient for me. Share this post Link to post
limelect 48 Posted April 6, 2020 My kind of work needs me to move from one directory to the other very often. Many but many times a day. Share this post Link to post
Fr0sT.Brutal 900 Posted April 6, 2020 From what I understood you can do the following: Enum all windows Find those which belong to explorer processes Check if these are hidden Terminate corresponding explorer processes Though it seems more wise to me to just handle the described situation in your software. Share this post Link to post
limelect 48 Posted April 6, 2020 (edited) @Fr0sT.Brutal One word. I tried. For the hidden, it did not help. No association to Explorer. If you think you know what hidden mean I am willing to learn. the fact is that even "Winspector - Ultimate Windows Spy Utility" did not help. The obvious fact that somehow the hidden disappear. It is a problem I never encounter. I cannot even make that happen. The only thing I am left with that ShellWindows.Count shows it exist. you can try , I am sure you will not be able to see the problem, or maybe yes? var ShellWindows: IShellWindows; if Succeeded(CoCreateInstance(CLASS_ShellWindows, nil, CLSCTX_LOCAL_SERVER, IID_IShellWindows, ShellWindows)) then Label2.Caption:=IntToStr( ShellWindows.Count); Edited April 6, 2020 by limelect Share this post Link to post
limelect 48 Posted April 6, 2020 The only thing left is to scan the memory. But if the hidden disappear somehow I cannot reproduce it since I do not understand how it happens Share this post Link to post
aehimself 396 Posted April 6, 2020 (edited) By the definition from MSDN (https://docs.microsoft.com/en-us/windows/win32/api/exdisp/nn-exdisp-ishellwindows) "IShellWindows interface Provides access to the collection of open Shell windows." [...] "A Shell window is a window that has been registered by calling IShellWindows::Register or IShellWindows::RegisterPending." Which means that if I want to, I can register any application as a shell window and you will see it in your collection. Maybe this is what you mean "hidden" as it is an instance of a shell window, which is NOT an Explorer process...? Edit: I suppose you already read this: "If the type is VT_UI4, the value of index is interpreted as a member of ShellWindowTypeConstants" ...which leads you here: "SWC_EXPLORER An Windows Explorer (Explorer.exe) window. SWC_BROWSER An Internet Explorer (Iexplore.exe) browser window. SWC_3RDPARTY A non-Microsoft browser window. SWC_CALLBACK A creation callback window. SWC_DESKTOP Windows Vista and later. The Windows desktop." So I suppose you are handling these cases in your code...? Edited April 6, 2020 by aehimself Share this post Link to post
limelect 48 Posted April 6, 2020 Ok, I did succeed to make a hidden explorer. How? by executing on D10.2.3 my software. I will keep you guys posted. Share this post Link to post
limelect 48 Posted April 6, 2020 (edited) Well we will meet again (and it might be a long time) when I have some news for you. Sorry, but it will take a long effort to find whats going on. It seems that d10.2.3 with my software does something to explorer. As I said the hidden comes and goes. However, the software on its own is full proof (i hope) and nothing like that happens. No complaints from people using it. I personally using it for years !! Thanks for your help Edited April 6, 2020 by limelect Share this post Link to post