sbeckett
Posts: 35
Joined: Thu Aug 25, 2005 12:12 am

Uninstall Custom Action to remove all folders?

I'm trying to write a custom action to remove the install directory at the end of the uninstall.

I'm using an vbscript InlineScript and entering the following as the Script text:

RMDir [TARGETDIR]

I've placed it into the Uninstall custom actions area, but it does not remove the directory.

I've been unable to find a good example of what the vbscript should be, or how the various Action segments map to uninstallation behavior.

I'm using synchronous execution, ignore return code; deferred execution; always execute; and REMOVE="ALL" AND NOT UPGRADINGPRODUCTCODE as the execution condition.

I have another custom action which is an executable in the same Uninstall Action area, and it's running just fine with the same options.
ciprian
Posts: 259
Joined: Thu Jul 14, 2005 12:56 pm
Location: Craiova, Romania
Contact: Website

Hi,

The problem with your script resides in the fact that in order to access a property from a VBScript you must use:

Code: Select all

Session.property("PropertyName")
Also, if you set your custom action to be executed as deferred, there is the possibility that the properties are not available anymore.

For more information on this topic please visit:
http://msdn.microsoft.com/library/defau ... actions.as

Here is an example of a VBScript that removes the TARGETDIR folder upon uninstall.

Code: Select all

   SET fso = CreateObject("Scripting.FileSystemObject")
   pathToFolder = Session.property("TARGETDIR")
   smallPath=Left(pathToFolder,Len(pathToFolder)-1)
   If (fso.FolderExists(smallPath)) Then
      fso.DeleteFolder(smallPath)
   End if
  
Create a VBScript file on you disk with this code.

You could use a "New Attached Custom Action" type of custom actiom. Set it to be executed as "Immediate" and edit the "Condition" field to REMOVE="ALL" AND NOT UPGRADINGPRODUCTCODE.

All the best,
Ciprian
Ciprian Burca
Advanced Installer Team
http://www.advancedinstaller.com
sbeckett
Posts: 35
Joined: Thu Aug 25, 2005 12:12 am

I realize this is rapidly becoming a VBScript tutorial, but I can't find very many resources to help with what I'm assuming is a common need: to remove the application folder on uninstall despite having created new files post-install. I would recommend putting that into the manual.

That being said, I tried creating a vbscript called rmdir.vbs

It contains:

Function removeInstallDir()
SET fso = CreateObject("Scripting.FileSystemObject")
pathToFolder = Session.property("TARGETDIR")
smallPath=Left(pathToFolder,Len(pathToFolder)-1)
If (fso.FolderExists(smallPath)) Then
fso.DeleteFolder(smallPath)
End if
End function

And is called from a "New Attached Custom Action" underneath Uninstall. The Function Name is given as removeInstallDir.

When I uninstall the application, the TARGETDIR is left untouched with all newly created files and subdirs still intact.
ciprian
Posts: 259
Joined: Thu Jul 14, 2005 12:56 pm
Location: Craiova, Romania
Contact: Website

Hi,

I used the script you sent me and created an uninstall custom action similar to yours but I encountered no problems.

Here is how I configured my custom action:

- I created a "New Attached Custom Action" under "Uninstall"
- I set it to be executed as "Synchronous execution check return code" and "Immediate".
- As a condition I used REMOVE="ALL" AND NOT UPGRADINGPRODUCTCODE.

I tested this custom action and the TARGETDIR was removed without any problems.

Hope this helps. If the problem persists, please send us the AIP file of the project to: support at advancedinstaller dot com.

All the best,
Ciprian
Ciprian Burca
Advanced Installer Team
http://www.advancedinstaller.com
sbeckett
Posts: 35
Joined: Thu Aug 25, 2005 12:12 am

I've been playing more with this and the vbscript custom action only works for the non-bundled JRE version of the installer.

I made an installer project for our program and added the custom uninstall action, an attached vbscript custom action to remove the install directory.

I then build both installers, one with and one without the bundled JRE.

I installed the one without the JRE and then uninstalled it without launching our program. It worked fine.

I installed the one without the JRE again and then ran our program. I then ran the installer to uninstall the program and it worked fine.

However, when I ran the installer with the JRE bundle and then tried to uninstall it without ever running our program, the uninstall hung with an error stating:

"There is a problem with this Windows installer package. A script required for this install to complete could not be run. Contact your support personnel or package vendor."

I have to run the MsiZip usitl from the MSFT dev tools in order to clear out the bundled-JRE version.

Why would they be so different? The build files are created at the same time. The only difference is that one has the JRE in the install dir.
ciprian
Posts: 259
Joined: Thu Jul 14, 2005 12:56 pm
Location: Craiova, Romania
Contact: Website

Hi,

The problem is with the Script. The JRE folder contains files that are read only. The script is set to delete only files that don't have this flag set. This is the reason behind the failing of the custom action.

The script should be:

Code: Select all

Function removeInstallDir()
    SET fso = CreateObject("Scripting.FileSystemObject")
    pathToFolder = Session.property("APPDIR")
    smallPath=Left(pathToFolder,Len(pathToFolder)-1)
    If (fso.FolderExists(smallPath)) Then
       fso.DeleteFolder smallPath, true
    End if
End Function
Best regards,
Ciprian
Ciprian Burca
Advanced Installer Team
http://www.advancedinstaller.com
sbeckett
Posts: 35
Joined: Thu Aug 25, 2005 12:12 am

Here's the exact script I'm using in the attached custom action.

Code: Select all

Function removeInstallDir()
	SET fso = CreateObject("Scripting.FileSystemObject")
	pathToFolder = Session.property("APPDIR")
	smallPath=Left(pathToFolder,Len(pathToFolder)-1)
	If (fso.FolderExists(smallPath)) Then
		fso.DeleteFolder(smallPath, true)
	End if 
End function
The action is set for synchronous, check return code, immediate execution.

The condition is REMOVE="ALL" AND NOT UPGRADINGPRODUCTCODE

When I try to uninstall, I get the same error

"There is a problem with this Windows installer package. A script required for this install to complete could not be run. Contact your support personnel or package vendor."

Again I have to zap the install with MsiZap.

Any further suggestions?

I'm running AI 3.8.1
gigi
Posts: 2103
Joined: Tue Apr 11, 2006 9:55 am
Contact: Website

Hi,

The problem resides with the script you used. You added round brackets when the DeleteFolder function is called. This causes the script to fail.

Here is how you could configure the Custom Action.

- You could place your custom action under the RemoveFolders standard action (add this by right clicking on InstallExecuteSequence->Show Standard Action->BeforeFileInstallation->RemoveFolders).

- Edit Function Name field to removeInstallDir.
The script should be like this:

Code: Select all

 
Function removeInstallDir()
   SET fso = CreateObject("Scripting.FileSystemObject")
   pathToFolder = Session.property("APPDIR")   
   smallPath=Left(pathToFolder,Len(pathToFolder)-1)
   If (fso.FolderExists(smallPath)) Then	
      fso.DeleteFolder smallPath, true
   End if
End function
- Set the custom action to be executed as "Synchronous execution check return code" and "Immediate"

Edit the "Condition" field to REMOVE="ALL" AND (NOT UPGRADINGPRODUCTCODE).

Please let me know if you encounter any problems.

Hope this helps you.

All the best,
Gigi
_________________
Gheorghe Rada
Advanced Installer Team
http://www.advancedinstaller.com
sbeckett
Posts: 35
Joined: Thu Aug 25, 2005 12:12 am

I had previously tried the script both with and without the parentheses and it made no difference.

However, putting it into the RemoveFolders standard action area appears to have made all the difference.

It is now working as expected.

Thanks!
awbranch
Posts: 2
Joined: Thu May 18, 2006 3:13 am

Causes AntiVirus Warning

This approach worked for me, except when the script runs, my Anti Virus Norton Internet Security complains of a malicious attack on my computer when the uninstall runs. Is there any other way that this can be accomplished short of writing an EXE?
gigi
Posts: 2103
Joined: Tue Apr 11, 2006 9:55 am
Contact: Website

Hi,

You can create an exe but I don't know if this solves the Anti Virus problem. However here is some code that could help you:

Code: Select all

void EmptyDirectory(char* folderPath)
{
	char fileFound[256];
	WIN32_FIND_DATA info;
	HANDLE hp; 
	sprintf(fileFound, "%s\\*.*", folderPath);
	hp = FindFirstFile(fileFound, &info);
	do
	{
		if (!((strcmp(info.cFileName, ".")==0)||
			(strcmp(info.cFileName, "..")==0)))
		{
			if((info.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)==
				FILE_ATTRIBUTE_DIRECTORY)
			{
				string subFolder = folderPath;
				subFolder.append("\\");
				subFolder.append(info.cFileName);
				EmptyDirectory((char*)subFolder.c_str());
				RemoveDirectory(subFolder.c_str());
			}
			else
			{
				sprintf(fileFound,"%s\\%s", folderPath, info.cFileName);
				BOOL retVal = DeleteFile(fileFound);
			}
		}

	} while(FindNextFile(hp, &info)); 
	FindClose(hp);
}
The EmptyDirectory function deletes all files and folders from a specified path. You must specify [APPDIR] property as parameter for the program that uses this function. Here's how the main function looks like:

Code: Select all

char fullPath[MAX_PATH] = "";

for(int i = 1; i < argc; i++)
{
	strcat(fullPath, argv[i]);
	if(i < argc-1) strcat(fullPath, " ");
}

if(strlen(fullPath)) EmptyDirectory(fullPath);
Here's how to use the exe program as custom action in Advanced Installer:
Switch to the "Custom Action" page and add a "New Attached Custom Action" under the "Uninstall" action and select the created exe. Use the following options for the custom action:
1. Command Line: [APPDIR]
2. Let all the other options to their default values.

Use this code at your own risk.

Regards,
Gigi
_________________
Gheorghe Rada
Advanced Installer Team
http://www.advancedinstaller.com
shaun1979in
Posts: 8
Joined: Mon Jul 10, 2006 2:12 pm

Cont.:Uninstall Custom Action to remove all folders?

Hi Again,
I was going through your forum database and came across this query that matches the issue that i am facing currently.

As per our client requirement i am writing two text files to Target Dir at run-time through vbscript added under install custom action.

I have followed all the steps and able to uninstall the application completely but still i am getting this error message post this:

"There is a problem with this Windows installer package. A script required for this install to complete could not be run. Contact your support personnel or package vendor."

The two file extentions that i am using are .bat and .msw files. Can u suggest some way out of this?? Or shall i send you the .aip file?

Regards
Shaun
gigi
Posts: 2103
Joined: Tue Apr 11, 2006 9:55 am
Contact: Website

Hi,

This error is related to your vbscript custom actions, that probably are not written properly (or you try to access those files before they are created). So please post here both vbscript files and options that you use for the custom actions.

Regards,
Gigi
_________________
Gheorghe Rada
Advanced Installer Team
http://www.advancedinstaller.com

Return to “Common Problems”