1

I´m developing a system that consist in a program that runs in the desktop (Windows).

Each minute detects if the active program is a browser and in this case checks if the url of the active tab is in a "black list"

In this case I would like to close the current tab of the browser. What I´m doing now is killing the browser process, and that means that tabs with urls not in the black list were closed too.

For detecting the url of the active tab, I´m using the solution from How to get the url from Chrome using delphi

I´m using Delphi 7, but a solution in any language will be appreciate.

Community
  • 1
  • 1
razonasistemas
  • 371
  • 1
  • 4
  • 11
  • 5
    Doesn't this depend upon the browser? – Andreas Rejbrand Dec 06 '12 at 19:05
  • 6
    This sounds like a horrible program. Surely you want to use a proxy? – David Heffernan Dec 06 '12 at 19:05
  • I see what you're trying to achieve, but I don't think this is a good way to do it. – Wouter van Nifterick Dec 06 '12 at 19:20
  • 4
    You know, all someone has to do to foil your scheme is to put a "forbidden" page in a *frame* hosted on a "permitted" site (which could even be a local HTML file). There are already more-effective ways of implementing blacklists, and they're probably cheaper than whatever it has cost your employer to have you working on this project for over a year. – Rob Kennedy Dec 06 '12 at 19:24
  • One simple way is retrieving its window handle and send Ctrl+F4/W message to it.... – Thunder-KC Inc Dec 06 '12 at 19:32
  • Like @DavidHeffernan says: this sounds like a very bad approach. Instead consider a browser add-in and intercept url before it's shown or server side (proxy) as David suggests... – Remko Dec 06 '12 at 20:13
  • 2
    Or using one of the millions of off the shelf products that already do this – David Heffernan Dec 06 '12 at 20:15
  • Our SonicWall Router achieves this as a form of content filtering. I can add blacklisted URL's there and it won't even allow the site to pass through to the computer in the first place. – Jerry Dodge Dec 07 '12 at 17:14

2 Answers2

1

I am using this methodology to close browser tabs. As you know, Chrome and Iexplorer uses different process for every tabs. I find process name and kill them. In the following code is killing all process in the memory for chrome or iexplore or what ever you want. Don't forget to add winapi.tlhelp32 unit in your uses line.

function KillTask(ExeFileName: string): Integer;
const
  PROCESS_TERMINATE = $0001;
var
  ContinueLoop: BOOL;
  FSnapshotHandle: THandle;
  FProcessEntry32: TProcessEntry32;
begin
  Result := 0;
  FSnapshotHandle := CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
  FProcessEntry32.dwSize := SizeOf(FProcessEntry32);
  ContinueLoop := Process32First(FSnapshotHandle, FProcessEntry32);
  // find all process and kill them all one by one    
  while Integer(ContinueLoop) <> 0 do
  begin
    if ((UpperCase(ExtractFileName(FProcessEntry32.szExeFile)) =
      UpperCase(ExeFileName)) or (UpperCase(FProcessEntry32.szExeFile) =
      UpperCase(ExeFileName))) then
      Result := Integer(TerminateProcess(
                        OpenProcess(PROCESS_TERMINATE,
                                    BOOL(0),
                                    FProcessEntry32.th32ProcessID),
                                    0));
     ContinueLoop := Process32Next(FSnapshotHandle, FProcessEntry32);
  end;
  CloseHandle(FSnapshotHandle);
end;
0

Use the following process:

  • Start recording a macro
  • Open a browser
  • Press the keyboard shortcut to close a tab
  • Stop recording the macro
  • Create a shortcut to the macro
Paul Sweatte
  • 24,148
  • 7
  • 127
  • 265