Recent

Author Topic: Close browser that I've opened with ShellExecute  (Read 9000 times)

bobonwhidbey

  • Hero Member
  • *****
  • Posts: 592
    • Double Dummy Solver - free download
Close browser that I've opened with ShellExecute
« on: July 30, 2015, 11:42:47 pm »
My app opens the default browser with:

    url := 'http://www. etc.'
    ShellExecute(aHandle, 'open', PChar(url), '', '', SW_HIDE);

How can I close this page/tab of the browser.
Lazarus 3.0RC2, FPC 3.2.2 x86_64-win64-win32/win64

lainz

  • Hero Member
  • *****
  • Posts: 4468
    • https://lainz.github.io/
Re: Close browser that I've opened with ShellExecute
« Reply #1 on: July 30, 2015, 11:45:37 pm »
You must retrieve the list of process running and kill the one is using that tab.

Depending of the browser one or multiple processes can be running for each tab.

You can try using TProcess that has more options, maybe is something that can help you.

But I say again the best is to include your own browser, I do that way and I don't have this kind of problems.

rvk

  • Hero Member
  • *****
  • Posts: 6163
Re: Close browser that I've opened with ShellExecute
« Reply #2 on: July 30, 2015, 11:51:32 pm »
You can't.

Even if you get the process which is running your page, you can't be sure if it's the only page it has open. Some browsers have one process for all pages. How would you want to close the right one. You just don't have enough control over displaying pages this way.

Like we said in the other thread... use a http-like component or use a TWebBrowser component where the page is displayed so you can close it.

If you really want to automate this I would choose the http-like component.

(and as also said already... logging in like this is no problem. My guess for your site it's just a post of your username and password to a specific page.)

molly

  • Hero Member
  • *****
  • Posts: 2330
Re: Close browser that I've opened with ShellExecute
« Reply #3 on: July 31, 2015, 12:06:49 am »
(and as also said already... logging in like this is no problem. My guess for your site it's just a post of your username and password to a specific page.)
I forgot to thank you for your reply on the other thread, so thank you.

Yes, it seems indeed a simple username + password that is used for the page to be displayed (at the most a special post request would be required to mimic filling the fields). So, if not mistaken the httpget example that is part of fcl-web is able to login to that page without modifying a single line of code -> compile -> run from shell -> supply url and then username + password.

The actual scraping part would be all that's left to do.

bobonwhidbey

  • Hero Member
  • *****
  • Posts: 592
    • Double Dummy Solver - free download
Re: Close browser that I've opened with ShellExecute
« Reply #4 on: July 31, 2015, 12:09:03 am »
I'm convinced - closing the browser, or any page of it, is a BAD idea.
Lazarus 3.0RC2, FPC 3.2.2 x86_64-win64-win32/win64

rvk

  • Hero Member
  • *****
  • Posts: 6163
Re: Close browser that I've opened with ShellExecute
« Reply #5 on: July 31, 2015, 12:17:14 am »
Yes, it seems indeed a simple username + password that is used for the page to be displayed (at the most a special post request would be required to mimic filling the fields). So, if not mistaken the httpget example that is part of fcl-web is able to login to that page without modifying a single line of code -> compile -> run from shell -> supply url and then username + password.

The actual scraping part would be all that's left to do.
And because bobonwhidbey is scraping his/her own pages on www.bridgebase.com the username and password could even be hardcoded in the program. My guess is that it's for own use (not distribution). And if it is for distribution the username and password could be stored in a simple .ini file so it wouldn't be given every time when the cookies run out. Ultimate automation is possible this way. Just run a .exe and your pages will be scraped. (no IE or browser window involved)


molly

  • Hero Member
  • *****
  • Posts: 2330
Re: Close browser that I've opened with ShellExecute
« Reply #6 on: July 31, 2015, 01:26:04 am »
@rvk:

hmz, the only mistake i've made, is that i've mistakenly have been looking at fixes branch for httpget.pas instead of the one provided with the latest lazarus (fpc 2.6.4). That's the crap with using multiple fpc installations -> it messes with the saw-dust between my ears :-(

Eugene Loza

  • Hero Member
  • *****
  • Posts: 674
    • My games in Pascal
Re: Close browser that I've opened with ShellExecute
« Reply #7 on: July 31, 2015, 09:35:45 am »
I've read that it's possible to make this through AJAX technology. I.e. you create a special web-page that 'listens' to your program at 127.0.0.1 and acts accordingly. I.e. you can close the page by sending a kind of 'window.close()' script through AJAX. That'd work only for specially created local pages, however, it might also work to close external pages/tabs.
However, I didn't analyze this stuff too deeply, just as a basic concept.
My FOSS games in FreePascal&CastleGameEngine: https://decoherence.itch.io/ (Sources: https://gitlab.com/EugeneLoza)

Thaddy

  • Hero Member
  • *****
  • Posts: 14373
  • Sensorship about opinions does not belong here.
Re: Close browser that I've opened with ShellExecute
« Reply #8 on: August 03, 2015, 10:52:28 am »
You can't.

Of course you can.

Find the windows handle
Send WM_CLOSE
Object Pascal programmers should get rid of their "component fetish" especially with the non-visuals.

rvk

  • Hero Member
  • *****
  • Posts: 6163
Re: Close browser that I've opened with ShellExecute
« Reply #9 on: August 03, 2015, 10:59:21 am »
You can't.

Of course you can.

Find the windows handle
Send WM_CLOSE
And you might close all other browser-tabs you have open too. There is no way to only close the tab you opened. At least, not without programming this for every multi-tab browser there is.

This was the question in the text:
Quote
How can I close this page/tab of the browser.

You might get away with sending ctrl+f4 (or w) to the correct tab but finding that tab is browser specific too.

Thaddy

  • Hero Member
  • *****
  • Posts: 14373
  • Sensorship about opinions does not belong here.
Re: Close browser that I've opened with ShellExecute
« Reply #10 on: August 03, 2015, 11:44:24 am »
My bad. But the heading says close browser.
Ergo, don't use shellexecute for that. It doesn't give you enough information in an easy way.
Depending on what you want there are several better options than the VB style ShellExecute.

Explain what you want *before* you decided to open a *hidden* tab in a browser.
Because that one is the wrong choice.
Object Pascal programmers should get rid of their "component fetish" especially with the non-visuals.

 

TinyPortal © 2005-2018