Jim Lawless' Blog


Removing IE Popups in C

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

Please note! If you're having difficulties compiling the C source code presented below, please see my post: Compiling C from the Command Line with Pelles C

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



Views expressed in this blog are those of the author and do not necessary reflect those of the author's employer. Views expressed in the comments are those of the responding individual.

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


About Jim ...


Click **here**
to try out MailWrench;
a command-line SMTP /
SMTPS (Google Gmail)
mailer for Windows.


Follow me on Twitter

http://twitter.com/lawlessGuy


Recent Posts

A JavaScript REPL for Android Devices

MailSend is Free

My Blog Engine

The October 10th Bug

A Review of Kevin Mitnick's Book Ghost in the Wires

Spellbound by Web Programming

Backlinks to my Blog Posts

Play MP3 Files with Python on Windows


Random Posts

WSH2EXE part 1

A GUI for urlx

Java in a Windows EXE with launch4j

My Journey Began with BASIC

Switching a Console Window to Full Screen or Windowed Mode

The Protection Racket

Rhino JavaScript to EXE with launch4j

Thwarting HTTP Referer Trackbacks

Checking Shift States with DEBUG

TAP : A Command Processor Library


Full List of Posts

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


Recent Posts from my Other Blog

Remembering Dr. San Guinary

Why Some Web Sites will go Dark on Jan 18th

SNL Superhero Skit

More Ruby Games

My Ruby Game Challenge Entry

Steal this Bookmarklet

Nerd Toys

Learn New Jargon, You Must

Spot the Wiebe

Tech Magazine Glory Days

Book Review : Paull Allen - Idea Man

A 90's Experiment in Online Systems - The U.S. West CommunityLink Service