Force Close of Explorer Opened w/ RUN

MSDN on TerminateProcess() mentions your handle must have " PROCESS_TERMINATE access rights".

…and who does one pay to gain such terminate privilege?

MSDN also states that the process handle returned by the CreateProcess function has PROCESS_ALL_ACCESS access…

My assumption here is that PROCESS_ALL_ACCESS does not include PROCESS_TERMINATE despite the implication that ALL could logically include TERMINATE.

How do I know @totalhip is using CreateProcess ?

We are 23 posts into this Topic and have ZERO Code and ZERO Error messages, we just know something does not work. He mentions OddJob uses CreateProcess … but for what methods is he calling? This is a snipe hunt.

Just ask Bruce. As I have said, the code is the OddJob demo app, and thus, the OddJob classes.
Job.CreateProcess(‘’,‘explorer.exe’, ‘’, ‘’)

The explorer text is substituted for notepad. I suppose the Capesoft class could have a CreateProcess method and instead do something else. However…

What are you actually trying to do with the Explorer instance that you launch ?

Quickly provide what users already know while at the same time bring them forward into a new and consistent folder/file structure for managing dept purchasing documents within their new purchasing application. The key word here is quickly.

A good point to keep in mind. Open/close a tab from an app would be acceptable too.

Can’t you just find the window handle and post it a WM_CLOSE?
I’m not sure I see any relationship between how you start it and how you close it.

It seems the handle must have " PROCESS_TERMINATE access rights" which is not automatically the case for explorer.

If the process has been created using CreateProcess or ShellExecuteEx, your program knows the TID of the main thread of that process (some work is required for that in case of ShellExecuteEx). Hence, your program can use the PostThreadMessage API function to post WM_CLOSE (or WM_QUIT, or other messages) to the message queue of that thread. Just the File Explorer remains alive if such messages have been posted from outside…

The desire is to also close the File Explorer that was created.

The solution that we chose (about 15+ years ago, using C6) was a combination of SysTree and SysList on a window. I made a couple of improvements to SysList so that it cached the icons of the various file types instead of looking up that info every time.

We also needed Explorer menus, which we paid Jim Kane to write that part.

Overall, the solution worked well enough. It was nice to limit the folders to the ones our app cared about.

A lot of work, though.

Exact same goal. Limited time (1 Jan 23). Will need to live with some compromise.

The Explorer-style Open/Save File dialog can do many things which are available with the File Explorer. Clarion FILEDIALOG could be used if to hide entry field where names of selected files are displayed and if to change text in buttons. There are ways to customize standard dialogs - see the article about “classic” approach to customization and another one about new customization interface. The customized file dialog can be executed in a program thread rather than a separate process in case of File Explorer.

1 Like

Thank you for pointing this out. Will take a look ASAP.

I saved this link a couple of years ago, it may give some extra background and alert about the hook approach

@also mentions Clarion’s RUN uses the createprocess api.

Here is some code which shows some of the differences createprocess can do, like inherited access tokens aka bInheritHandles.

There is a lot of info on this thread to call a process or run a program.

I havent looked at calling Explorer so I dont know if its different but SysInternals ProcessExplorer should give you the necessary insight. You can see partial screenshots of ProcessExplorer in that link to the thread posted just above which shows the difference between the bInheritHandles.

As there is code there, you could trying using it to call Explorer and then see if Oddjob can kill it.

Dont know if its something OddJob should be able to do or not though.