Silverfrost Forums

Welcome to our forums

close browser opened by shellexecute

7 Apr 2018 1:41 #21743

I can successfully open my default browser by using the winapi function 'ShellExecute' in my fortran application. Using the winapi function GetActiveWindow I can get the handle to the browser window and manipulate it as needed. Does anyone know a way either in fortran or via the winapi to close the browser window once it is no longer needed?

7 Apr 2018 8:06 #21748

I don't know of a method to close a remote application. The DestroyWindow function will not work (according to the documentation). You might be able to use SendMessage with WM_CLOSE (the documentation does not say that this doesn't work).

If you have the time and interest, you can create your own browser (that accesses the Microsoft engine) by calling winio@ and using %wb. See ftn95.chm for details.

7 Apr 2018 9:58 #21750

Current Fortran actually is so powerful and useful even for such tasks so that the people who use only C/C++ are often left in the dust.

I think we discussed this around 10 years ago, try to Search, here was great patriot of Fortran John Horspool who suggested it, Eddie also contributed. I used it to monitor if some EXEs are running to stop them. It will find PID of your browser process in Control Panel and delete the job.

The idea is simple as 2x2: try in Command Prompt this to get the idea what's to do:

tasklist /v >zzzzz

This will produce you file zzzzz containing all running processes. Your Fortran code will do that for you, then read zzzzz file, then find the browser PID and then execute another command which will stop specific PID

taskkill /F /pid XXXX

where XXXX is Browser's PID from the file zzzzzz

UPDATE: here is the link with the full demo: https://forums.silverfrost.com/Forum/Topic/851&highlight=process

7 Apr 2018 1:17 #21756

Paul: Thank you. You are right: I had already tried DestroyWindow and SendMessage (WM_Close) before I posted. Neither worked. DanRRight: thanks, I'll give that a try.

7 Apr 2018 4:14 #21761

Killing the task would not give a clean exit but it might be the only way.

8 Apr 2018 7:25 #21772

DanRRight: Thanks for the tip. I found the original post you had included, it was very easy to program in Fortran, works just fine.

Paul: After a kill, chrome complains the next time it is opened, but without harming what I need to get accomplished the next time I call in in fortran. Now that I have Dan's method up and running, is there a more 'gentle' way to exit a program, given I have the correct process ID?? I assume 'kill' is identical to hitting the 'X' window button on the upper right?

9 Apr 2018 5:06 #21779

The only thing that I can find is the following link but it looks tricky...

https://support.microsoft.com/en-us/help/307395/how-to-use-visual-c-to-close-another-application

Please login to reply.