2
votes

I'm writing a C++ function in a standard dll to delete files in a folder during uninstall. These files were added by the application at some point.

I'm using DeleteFile to delete the files one by one. The DeleteFile is returning an ERROR_ACCESS_DENIED error. The DeleteFile is called from the InstallShiel uninstall as a custom action during After InstallValidate when REMOVE="ALL".

Any ideas why I'm getting ERROR_ACCESS_DENIED? I'm uninstalling as an administrative user.

The InstallShield poject is a Basic MSI Project install. I'm using InstallShield Spring 2012 professional.

The Delete function works correctly when called from a normal test application (Windows Forms Application). The Dll is a Win32 dll.

3

3 Answers

1
votes

What type of files are these and where are they located? If the files are to be considered user data I would not remove them at all.

Use MSI's RemoveFile table whenever possible to remove files on install or uninstall. It is way too error prone and time consuming to use custom actions.

1
votes

Remove file table will work, but not if the .exe calling the DLL is in use. If this is the case you can place a custom action with the condition REMOVEALL=TRUE, then simply kill the process.

You will want to put this earlier in the InstallExecute sequence so that it runs in silent mode.

For example, in VBScript:

Dim oShell : Set oShell = CreateObject("WScript.Shell")
oShell.Run "taskkill /im exeprocessname.exe", , True
0
votes

This problem was caused because the dll with the function being called is in the folder being deleted.