Click here to Skip to main content
15,747,030 members
Articles / Programming Languages / C++
Posted 9 Jun 2002


30 bookmarked

Clean Up Handler

Rate me:
Please Sign up or sign in to vote.
5.00/5 (1 vote)
9 Jun 2002CPOL2 min read
A shell extension to delete temporary files (e.g visual c++ intermediate files).

Sample Image - cleanup.jpg


Windows introduced a new concept when it let the user add new handlers to the shell, such as a context menu handler, icon handler and also for other applications such as the cleanup manager.

Generally all the handlers implement a certain interface (one or more) and register the component by adding some keys to the registry.


This Application is a simple COM component that implement the IEmptyVolumeCache2 interface and its 6 methods.

Class CExtHandler : public IEmptyVolumeCache2 {
     //IUnknown interface 

    //IEmptyVolumeCache interface 
    STDMETHODIMP Initialize(
             HKEY hkRegKey,
             LPCWSTR pcwszVolume,
             LPWSTR *ppwszDisplayName,
             LPWSTR *ppwszDescription,
             DWORD *pdwFlags);

    STDMETHODIMP GetSpaceUsed( 
             DWORDLONG *pdwlSpaceUsed,
             IEmptyVolumeCacheCallBack *picb);
     STDMETHODIMP Purge( 				// Called when it's time to delete.
             DWORDLONG dwlSpaceToFree,
             IEmptyVolumeCacheCallBack *picb);
    STDMETHODIMP ShowProperties(HWND hwnd);
    STDMETHODIMP Deactivate(DWORD *pdwFlags);

    //IEmptyVolumeCache2 interface 
    STDMETHODIMP InitializeEx (HKEY hKey, LPCWSTR pcwszVolume, LPCWSTR pcwszKeyName,
                               LPWSTR *ppwszDisplayName, LPWSTR *ppwszDescription, 
                               LPWSTR *ppwszBtnText, DWORD *pdwFlags);

How it works:

  • You first register the server (through regsrv32.exe, or indirectly by reg.bat) and you'll be presented with
    a dialog box, where you could fill the fields appropriately or let those default values, if you want the clean
    handler to delete the intermediate visual c++ files.
  • Once the extension is registered, it can be accessed by starting CLEANMGR.EXE or by clicking the "Disk Cleanup" button on a drive's Properties dialog in Explorer. The Properties dialog can be accessed by right-clicking on a drive in Explorer and selecting "Properties" from the context menu or by clicking on a drive in Explorer and selecting File then Properties.
  • When you don't need it anymore simply unregister the server, and delete the DLL file.


When I first registered my component and ran the cleanup manager (cleanmgr.exe), thus launching my brand-new cleanup handler, I was amazed by the the size of the intermediate files that Visual C++ has generated for its need (about 200 Mb).

Though this handler was intended to delete the files that visual C++ has generated, it can also be used for other application temporary files or other purpose.

It has been tested only on windows XP, please tell me it work on your machine. If you found this application of help, let me know at


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Written By
Software Developer (Senior)
Canada Canada
Begin programming in pascal some 8 years ago, then to assembly and C, after seeing that pascal is out of fashion. play a little with Delphi and C++ Builder, to see that was enough.

A little mess with other technologies, HTML, CGI, DHTML, PHP.

Comments and Discussions

Questionin windows 7/8 Purge API works fine, but not in Windows10 Pin
vinay.yalams17-Aug-16 23:40
vinay.yalams17-Aug-16 23:40 

I have a question, I'm trying to purge the thumbnails and I'm using the API Purge as mentioned above and it works well for windows 7/8. Is there anything that changed in windows 10?. I could see that same implementation doesn't work with Windows 10 when I try to clear the thumbnails?

Any thoughts on this would be greatly appreciated and thanks in advance for your time.
QuestionWindows 7 Pin
flapster196612-Dec-14 6:00
flapster196612-Dec-14 6:00 
GeneralDLLRegisterServer Pin
Peter Ritchie27-Jan-04 7:30
Peter Ritchie27-Jan-04 7:30 
GeneralUnicode Build Pin
Blake Miller29-Aug-03 9:23
Blake Miller29-Aug-03 9:23 
Generalhelp !!! Pin
mr_nishantpant6-Feb-03 14:38
mr_nishantpant6-Feb-03 14:38 
GeneralRe: help !!! Pin
David Crow30-May-03 7:21
David Crow30-May-03 7:21 
GeneralRe: help !!! Pin
mr_nishantpant30-May-03 8:08
mr_nishantpant30-May-03 8:08 
GeneralRe: help !!! Pin
Blake Miller20-Aug-03 15:34
Blake Miller20-Aug-03 15:34 
GeneralError!! Pin
WREY20-Sep-02 15:46
WREY20-Sep-02 15:46 
GeneralRe: Error!! Pin
Anonymous21-Sep-02 2:39
Anonymous21-Sep-02 2:39 
GeneralNice Pin
Andreas Saurwein11-Jun-02 0:40
Andreas Saurwein11-Jun-02 0:40 
GeneralRe: Nice Pin
Black Horus13-Jun-02 13:57
Black Horus13-Jun-02 13:57 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.