Find and uninstall junk programs -- from a batch file

As you’ll probably guess from its name, Crap Killer is a tool which scans your PC, trying to find browser toolbars and other junk, then offers to help you remove them.

This is all extremely basic, though. There’s no special detection of spyware here; if a program doesn’t appear in the Add/ Remove Programs applet then Crap Killer won’t find it. And there’s nothing to remove unwanted programs, either. All you can do is launch their official uninstaller.

What’s more, when we tested Crap Killer, it suggested removing plenty of perfectly legitimate applications (Freemake Video Converter, for example). Accuracy isn’t a strong point.

So, why are we telling you about this? There’s one main reason: Crap Killer is a batch file. That alone makes it a real technical achievement, but it also means you can freely edit its code to suit your own needs. Open the script in Notepad and you’ll find a line like this (only much, much longer).

@set include_list= /c:"toolbar" /c:"bar " /c:"coupon" /c:"shopp" /c:"shop to " /c:"shopat" /c:"shop at " /c:"arcade" /c:"price" /c:"deal" /c: "free"

Crap Killer works by scanning through your list of installed programs, and highlighting any which contain these keywords in its name. Using /c: "free" causes a problem because it appears in many legitimate programs, but as this is a batch file, you can just open it, remove that keyword, and try again. Easy.

The script’s detection algorithm is still almost entirely useless, of course, but again, because this is a batch file, you can reinvent it for some other purpose. What if you would like an easier way to remove a particular set of programs from your PC? Then you might replace the above line with something like this:

@set include_list= /c:"Adobe" /c:"Google" /c:"Nvidia"

Run the script now and it will list only Adobe, Google and NVIDIA programs. Launch the script with an /auto command line switch and it’ll even run each uninstaller automatically.

If you sometimes create batch files yourself, though, Crap Killer’s real value could be as an example of just what can be done. Are you curious how a batch file can find and process the list of installed applications, perhaps? Take a look at this (we’ve cut it down from the original, but the core remains).

FOR /F "tokens=1 delims=|" %%n IN (‘reg query HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall /s ^& reg query HKLM\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall /s 2^>nul ‘) DO echo %%n >> "%tmp%\tmpUC.txt"

Don’t worry about the precise syntax, just look at the basic structure: a For loop repeatedly calling the reg.exe tool, querying the Registry keys listing your installed applications, and saving the results as a file. Very nicely done.

There’s plenty more, too, from a simple trick to create a progress indicator, to a technique where Crap Killer elevates itself to gain admin rights (cheating, basically, though in a clever way). It may be a feeble junkware detector, but this is a very impressive batch file, with a range of interesting ideas which you can freely reuse in your own scripts.

© 1998-2015 BetaNews, Inc. All Rights Reserved. Privacy Policy.