Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles / Languages / C#

Start Menu Cleaner .NET

4.00/5 (6 votes)
22 Mar 2009Ms-PL2 min read 29.2K   288  
Start Menu Cleaner .NET (fka. Start Menu Cleaner for Windows XP) is a small utility that scans all dead shortcuts and empty folders on your Programs in Start menu. Tested on Windows XP, Vista, and W7

Introduction

A not so very old code submission on CodePlex, it was popular there and already got some reviews on the other site, so I thought of adding it here too. :)

Here's the screen shot, and I intentionally renamed the target files from those shortcuts for the demo since I accidentally deleted them all using that utility I made. I forgot to write the condition where it deletes only the checked items .. but don't worry, that was already fixed ;)

And another one from Windows Vista:

Background

I came across a problem again (I'm a "When there's a problem, I make the solution" guy) where I used a tool WinStep Start Menu Organizer to manage my programs in start menu, and I organize them the way I can easily open them (e.g. my Visual Studio and other Software development programs are in Developer Tools folder) instead of having my programs scattered or sorted and viewed on a 2 or more columns of installed programs.. Yuck! That's a great tool by the way ... BUT!!

Talk about CONS from that tool.. Since I managed them so perfect, the problem sets in when I started to uninstall lots of my unused applications. Why, what is that? You could guess ... DEAD SHORTCUT LINKS! Their Uninstaller left a dead shortcut files in my start menu, because the uninstaller didn't find them and just left them there. Well it's a user's fault. ;)

So just to save my time tracking down those dead shortcuts, I wrote a small utility, an open source and free for all program. Since it grows a bit, I also added a feature to scan empty folders.

Using the Code

Just download the latest release, extract it, and run StartProgramCleaner.exe.

Some code that you might be interested in here is, I used IWshRuntimeLibrary for handling shortcut files, such as getting the Target Path or Description from the shortcut file.

IWshRuntimeLibrary can be found in Windows Script Host Object Model (C:\Windows\System32\wshom.ocx).

Just reference it and use it:

C#
using IWshRuntimeLibrary;

Here's a little code snippet on how to do it:

C#
private static string GetTarget(string shortcut_file)
{
   IWshShortcut shortcut = (IWshShortcut)wsh.CreateShortcut(shortcut_file);
   string t = string.Empty;
   if (shortcut.TargetPath != string.Empty)
   {
      t = shortcut.TargetPath;
   }         
   shortcut = null;
   return t;
}

private static string GetDescription(string shortcut_file)
{
   WshShell shll = new WshShell();
   IWshShortcut shortcut = (IWshShortcut)shll.CreateShortcut(shortcut_file);          
   string d = shortcut.Description;
   shortcut = null;
   return d;
}

Points of Interest

This is from the latest release (which is Release 2).

I didn't know this was working fine in Vista or 7 until I saw some reviews on the internet! Thanks guys! and Thanks to that JUNCTION FOLDERS!

History

  • 22nd March, 2009: Initial post

License

This article, along with any associated source code and files, is licensed under The Microsoft Public License (Ms-PL)