Click here to Skip to main content
15,885,546 members
Articles / Programming Languages / C++

Clean Up Handler

Rate me:
Please Sign up or sign in to vote.
5.00/5 (1 vote)
9 Jun 2002CPOL2 min read 84.3K   1.7K   30  
A shell extension to delete temporary files (e.g visual c++ intermediate files).
#include "Cleanup.h"
#include "Resource.h"

extern HINSTANCE hDllInstance;

STDAPI DllUnregisterServer (VOID)
{
    HRESULT     hResult     = S_OK;
    LRESULT     lResult     = NOERROR;
    HKEY        hKey        = NULL;
    TCHAR       szClsid[MAX_PATH] = TEXT("");
    TCHAR       szSubKey[MAX_PATH] = TEXT("");
    TCHAR       szDisplay[MAX_PATH] = TEXT("");
    TCHAR       szEmptyVCSubKey[MAX_PATH] = TEXT("");

    //
    //  Load some necessary string values
    //
    LoadString (hDllInstance, IDS_CLSID, szClsid, MAX_PATH);
    LoadString (hDllInstance, IDS_DISPLAY, szDisplay, MAX_PATH);
    LoadString (hDllInstance, IDS_EMPTYVC_SUBKEY, szEmptyVCSubKey, MAX_PATH);

    //
    //  Delete the key HKCR\CLSID\{CLSID}\InprocServer32
    //  Delete the key HKCR\CLSID\{CLSID}\DefaultIcon
    //
    wsprintf (szSubKey, TEXT("CLSID\\%s"), szClsid);
    lResult = RegOpenKeyEx (HKEY_CLASSES_ROOT, szSubKey, 0, KEY_ALL_ACCESS, &hKey);
    if (lResult == NOERROR)
    {
        lResult = RegDeleteKey (hKey, TEXT("InprocServer32"));
        if (lResult != NOERROR)
            hResult = SELFREG_E_CLASS;

        lResult = RegDeleteKey (hKey, TEXT("DefaultIcon"));
        if (lResult != NOERROR)
            hResult = SELFREG_E_CLASS;
        RegCloseKey (hKey);
    }
    else
        hResult = SELFREG_E_CLASS;

    //
    //  Delete the key HKCR\CLSID\{CLSID}
    //
    lResult = RegOpenKeyEx (HKEY_CLASSES_ROOT, TEXT("CLSID"), 0, KEY_ALL_ACCESS, &hKey);

    if (lResult == NOERROR) 
    {
        lResult = RegDeleteKey (hKey, szClsid);
        if (lResult != NOERROR)
            hResult = SELFREG_E_CLASS;
        RegCloseKey (hKey);
    }
    else
        hResult = SELFREG_E_CLASS;

    //
    //  Delete the key HKLM\Software\Microsoft\Windows\CurrentVersion
    //                   \Explorer\VolumeCaches\CleanupSample 
    //
    lResult = RegOpenKeyEx (HKEY_LOCAL_MACHINE, szEmptyVCSubKey, 0, KEY_ALL_ACCESS, &hKey);

    if (lResult == NOERROR)
    {
        lResult = RegDeleteKey (hKey, szDisplay);
        if (lResult != NOERROR) hResult = SELFREG_E_CLASS;

        RegCloseKey (hKey);
    }
    else
        hResult = SELFREG_E_CLASS;

    return hResult;
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

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