Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles
(untagged)

Clean Up Handler

0.00/5 (No votes)
9 Jun 2002 1  
A shell extension to delete temporary files (e.g visual c++ intermediate files).

Sample Image - cleanup.jpg

Introduction

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.

Implementation

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.

Conclusion

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 blackhorus@caramail.com

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here