0

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.

Paul R
  • 208,748
  • 37
  • 389
  • 560
karizma
  • 13
  • 2
  • If the uninstaller just needs to delete some directory or files you can use some syscalls. Take a look at https://stackoverflow.com/questions/2256945/removing-a-non-empty-directory-programmatically-in-c-or-c – knightrider Oct 16 '15 at 08:26
  • This is generally a problematic idea because Windows is multi-user. User-generated files could be owned by multiple different users, none of which is the Administrator executing the uninstaller. The idea _is_ valid for applications that are installed by a single non-admin user (i.e. outside `Program Files` ) – MSalters Nov 04 '15 at 09:16

1 Answers1

0

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.

PhilDW
  • 20,260
  • 1
  • 18
  • 28
  • Thanks for the useful links @PhilDW. Could you please look at my updated question. – karizma Nov 04 '15 at 09:04
  • You'll need to be more explicit about "write code". Does that mean you don't know about the DeleteFile Win32 API? Or FindFirstFile/FindNextFile? That's the code you'd need. – PhilDW Nov 04 '15 at 16:38