Noob with VBS custom action problems - Advanced Installer Community
Scort
Posts: 4
Joined: Wed Mar 11, 2015 9:54 am

Noob with VBS custom action problems

HI All,

Absolute novice here so this is probably going to sound stupid but here goes!

Im building an installer that will place 4 files into a folder that already contains files of the same names. I want to save the original files so I have used the move/copy function to essentially just rename the original files but leave them in the same folder. This works fine and I have been using this for a while.

Now though I want to add this. Upon un install i want to run a real basic VB script as a custom action to rename the original files back to the correct file name. The script is as follows

Set objFSO = CreateObject("Scripting.FileSystemObject")
objFSO.MoveFile "renamed.txt" , "original.txt"

This works exactly as intended if i run it on its own, but when I add it to the installer as an installed file custom action, I just get an error saying the script wouldn't run.

Ive checked the unistall and modify check boxes, and the script is placed after add resources. The script is installed by the package fine but i just cant get to to execute on unistall :(

Help!!
Eusebiu
Posts: 4971
Joined: Wed Nov 14, 2012 2:04 pm

Re: Noob with VBS custom action problems

Hi and welcome to Advanced Installer forums.

Thank you for your interest in Advanced Installer.

Your VBS custom action cannot be executed on uninstall because it is already removed at that point. The files are removed during the "Remove Resources" action group which is executed before the "Add Resources" action group where you placed your custom action.

The recommended approach for you is to add your VB script as a "Launch attached file" custom action, so it will be embedded into the MSI package and you will be able to execute it at any point of the uninstallation.

Let us know if this helped, otherwise give us more details about your scenario.

Best regards,
Eusebiu
Eusebiu Aria - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube
Scort
Posts: 4
Joined: Wed Mar 11, 2015 9:54 am

Re: Noob with VBS custom action problems

Hi and thanks for the swift response! I will try that's shortly and let you know.

One other thing though, with the function and action boxes they are currently blank, should I populate these and if so what with?

Thanks again

Joe
Eusebiu
Posts: 4971
Joined: Wed Nov 14, 2012 2:04 pm

Re: Noob with VBS custom action problems

You're welcome Joe.

It is not necessary to populate those fields. The "Function" field is populated automatically only if you have functions defined in your script and the "Action Data" field should be populated if you want to send some properties to your custom action when it is executed as "deferred".

You can read more details about these options in the Custom Actions List article.

Best regards,
Eusebiu
Eusebiu Aria - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube
Scort
Posts: 4
Joined: Wed Mar 11, 2015 9:54 am

Re: Noob with VBS custom action problems

Hi, so I have tried adding the script as an attached file but it is still coming up with an error when uninstalling saying the script can't be run :( do you have any more thoughts? As I said I can run the script just fine on it's own but I can't get the uninstall to run it :(
Eusebiu
Posts: 4971
Joined: Wed Nov 14, 2012 2:04 pm

Re: Noob with VBS custom action problems

Hi,

Your script code search for the "renamed.txt" file in the same folder as the VBS file, but if because the file is added as an attached custom action, it will not be located in the same folder as the file that it tries to rename. In this case the TXT file is not found and the custom action returns an error.

In this case you need to specify the full path to the file that should be renamed and to the destination file. You can use the APPDIR property in this case and the "Action Data" field if the custom action is executed as deferred. As in the example below:

Code: Select all

folder = Session.Property("APPDIR")
source = folder + "renamed.txt"
dest = folder + "original.txt"
Set objFSO = CreateObject("Scripting.FileSystemObject")
objFSO.MoveFile source , dest
Just let me know if this worked.

Best regards,
Eusebiu
Eusebiu Aria - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube
Scort
Posts: 4
Joined: Wed Mar 11, 2015 9:54 am

Re: Noob with VBS custom action problems

Hi thanks again for your help. Ive got a little further! So I tried the code that you gave me but that didnt seem to work either. I spent a bit more time and basically i can get it to work fine with the original code I created if,

1. Under 'execution time' instead of 'immediately', i check 'after the system has successfully been modified'.
2. I uncheck 'fail installation if custom action fails....'

So its working as intended now , the only bug is that if i check the fail installation box again, it will still pop an error. So something is still not quite right?

Kind Regards

Joe
Eusebiu
Posts: 4971
Joined: Wed Nov 14, 2012 2:04 pm

Re: Noob with VBS custom action problems

Hi Joe,

I'm not sure why the code that I posted did not work for you because I tested it on my machine and it worked well for me.

Of course, if the "Fail installation if custom action returns an error" option is unchecked, the error will not appear even if the custom action was not finished successfully. This is why you get the error when that option is checked and do not take it when the option is unchecked.

As I mentioned in my previous thread, your custom action fails, most likely because it does not find the file that should be renamed.

Best regards,
Eusebiu
Eusebiu Aria - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube

Return to “Common Problems”