When you say "I have worked on it for some time" I take it that means you have tried sending the WM_CLOSE message to the window, since this is the most straightforward approach, and it usually works.Some time ago I tried to get help to close a web page from a program once it had been opened with SYS "ShellExecute", @hwnd%, "open",URL$, 0, 0, 1. Unfortunately, I was unable to achieve this although I have worked on it for some time.
I appreciate, of course, that the difficulty with sending WM_CLOSE is that you need to know the window handle, and that isn't straightforward when it's a window opened with SYS "ShellExecute". However it's not impossible, Google finds this StackOverflow article explaining how you can do it. First you need the Process ID, there is code for that at the BB4W wiki: pass the sei.hProcess% value to GetProcessId.
Having got the process ID you can then use SYS "EnumWindows" to find the top-level window which belongs to that process (again, there's BB4W code for that at the wiki). I hasten to add that I've not tried it myself, but if StackOverflow can be believed it's fairly straightworward. You could usefully write a BBC BASIC function which behaves like ShellExecute but returns a window handle.
I should add that there are easier ways of finding the window handle if you can be confident that the window in which you are interested is the only one belonging to a specific class or having a specific name. Then it's just a case of calling FindWindow. But that approach will fail if there are two or more windows with the same class/name.
Again, if you already know the window handle (in which case you should be able to close the window directly) you can also artificially send a mouse click to that window with the WM_LBUTTONDOWN message. One problem with that approach is that the top-level window of which you have the handle may not be the same window that is expecting mouse input.Please can someone advise how the program could automatically accept input without the user requiring to left-click on the screen?
So have you really exhausted the methods that are readily found with a web search? With this sort of problem Google is definitely your friend!