Jim Lawless' Blog


Removing IE Popups in C

Originally published on: Thu, 16 Jul 2009 03:24:17 +0000

Several years ago, popup ads began to plague my web-browsing experience. At the time, I used only IE as my browser, so I sought out a solution specifically for IE. I wrote a short C program that I called popnix. The version of popnix below is an early console-mode variant of the code. I later put a GUI on the program and gave it to a few friends who were quite happy with the results.

I should state that although this code was really targeted for IE 5 and 6, it still seems to work with version 7 even though IE now has its own blocking mechanisms. I haven't tried IE 8, yet.

Please note that popnix may not function properly if you're running with lower-level privileges as it tries to close an application that it did not invoke.

popnix.c


// License: MIT / X11
// Copyright (c) 2009 by James K. Lawless
// jimbo@radiks.net http://www.radiks.net/~jimbo
// http://www.mailsend-online.com
//
// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation
// files (the "Software"), to deal in the Software without
// restriction, including without limitation the rights to use,
// copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following
// conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
// OTHER DEALINGS IN THE SOFTWARE.
//
// Simple popup remover for Internet Explorer. Only one
// IEFrame window will be allowed open at any time.

#include <windows.h>
#include <stdio.h>

#pragma comment(lib, "user32.lib")

BOOL CALLBACK enumProc(HWND h,DWORD d);

HINSTANCE hInst;
HWND theWindow=0;

main() {
   printf("Popnix v1.5\n");
   for(;;) {
      EnumWindows((WNDENUMPROC)enumProc,0);
      Sleep(1000);
   }
}

BOOL CALLBACK enumProc(HWND h,DWORD d) {
   char buff[256];
   char *p;

      
   GetClassName(h,buff,255);
   if(!stricmp(buff,"IEFrame")) {
      if(IsWindow(theWindow)&&h!=theWindow) {
         GetWindowText(h,buff,254);
          printf("Closing %s\n",buff);
          MessageBeep(0);
          PostMessage(h,WM_CLOSE,0,0L);
      }
      else {
         theWindow=h;
      }
   }
   return TRUE;
}

The code loops continuously, until interrupted with a CTRL-C or a CTRL-BREAK. At one-second intervals, popnix iterates through the list of top-level windows, looking for any with a classname of "IEFrame". If an IEFrame window is found and it's not the first IEFrame window found, popnix tries to remove the popup.

Popnix first displays a message, then invokes a sound via a call to MessageBeep(0), then it finally posts a WM_CLOSE message on the offending window's message queue.

Later versions had more features and were more flexible about allowing some popups but not others. The above reference version attempts to close all other IEFrame popup windows, even if they are "good" popups.

Unless otherwise noted, all code and text entries are Copyright ©2009 by James K. Lawless

del_icio_us Save to del.icio.us
stumbleupon Save to StumbleUpon
digg Digg it
reddit Save to Reddit
facebook Share on Facebook
twitter Share on Twitter
aolfav More bookmarks



Previous post: Obfuscated Perl
Next post:A Simple ROT13 Macro


Search this Blog (and site)

Search this Site with PicoSearch


Subscribe to this Blog

 Subscribe!


Contact Me

Email: jimbo@radiks.net


Follow me on Twitter

http://twitter.com/lawlessGuy


Recent Posts

Mad Schemes : Learning Lisp via SICP

Auto Save Clipboard Images Redux

Extending SpiderMonkey JavaScript on Windows

Rhino JavaScript to EXE with launch4j

Compiling Rhino JavaScript to Java

Directory Traversal in Rhino JavaScript

Taking Shape

We've Moved!


Popular Posts

A Command-Line MP3 Player for Windows

Auto Save Images from the Clipboard

Java in a Windows EXE with launch4j

An Interview with Tom Zimmer: Forth System Developer

Setting Windows Console Text Colors in C


Random Posts

Changing the C64 Text Color in C

A Quine in Forth

Blog Posts by Category

An Interview with Tom Zimmer: Forth System Developer

Taking Shape

An Embedded Mini-Interpreter

Scott Ballantyne: Blazin' Into Forth

Obfuscated Perl

Invoking the Default Windows Screen-Saver

Stacking Images with PerlMagick


Full List of Posts

http://www.mailsend-online.com/bloglist.htm


Blogroll

MicroISV on a Shoestring
DadHacker
The Bottom Feeder
Writin' That Code!
The Recursive ISV
The Thomsen Blog
Prototypically Speaking
The Reinvigorated Programmer