Search code examples
c++windowsvisual-studio-2008custom-action

How to write a custom uninstaller code in C++ for deleting user generated files in Visual Studio 2008


I have read many articles and blogs online on writing a custom action in Visual Studio, however the approach for doing the same is not at all clear to me. My setup project is in C++. Can anyone please guide step-by-step how to go about writing a custom uninstaller in C++.

My setup project creates the following file structure:

Setup

-->Input-->file.txt

-->Program-->PrimaryOutput(Active)

-->Output

On successfull, run of the setup, files are created inside the output folder, which remains there during unistall of the setup. How can I write a custom uninstaller in c++ for completely deleting all files after uninstall.

Edit: I have been able to create custom action template like this:

#include "stdafx.h"

extern "C" UINT _stdcall Install(MSIHANDLE hInstall)
{
    return ERROR_SUCCESS;
}

extern "C" UINT _stdcall Commit(MSIHANDLE hInstall)
{
    return ERROR_SUCCESS;
}

extern "C" UINT _stdcall Rollback(MSIHANDLE hInstall)
{
    return ERROR_SUCCESS;
}

extern "C" UINT _stdcall Uninstall(MSIHANDLE hInstall)
{
    return ERROR_SUCCESS;
}

How should I proceed to write code for deleting Output folder in Uninstall method.


Solution

  • There is this: http://www.codeproject.com/Articles/570751/DevMSI-An-Example-Cplusplus-MSI-Wix-Deferred-Custo

    and VS custom actions are deferred, so it will work for you.

    or this:

    http://www.codeproject.com/Articles/1747/MSI-Custom-Action-DLL

    That's where you start anyhow.

    If you were using any other install tool it would give you access to the MSI's RemoveFile functionality, so would not need a custom action of any kind.