CainX
Posts: 3
Joined: Tue Dec 17, 2019 6:06 pm

MSI form a EXE that will delete itself after install?

I am attempting to create an installer from a .exe that will delete itself after the install. I have created the msi from the .exe with the required parameters, but I am not figuring out how to add a custom action to either run my current .bat script to delete the installer msi, or a custom action itself to delete it.

The use case is that it is a piece of software at my organization that we do not want distributed widely, but we are being asked to have it available for unmanaged machines by management. The parameters in the install contains the license key.

I appreciate any advice or thoughts
Catalin
Posts: 6608
Joined: Wed Jun 13, 2018 7:49 am

Re: MSI form a EXE that will delete itself after install?

Hello and welcome to Advanced Installer forums,

I think that you can achieve that by proceeding as it follows:

- add your .BAT file in your Advanced Installer project (e.g. "Files and Folders" page --> "Application Folder")

- in "Custom Actions" page, add a "Launch File" custom action without sequence (by pressing the "Add custom action without sequence" button which is placed to the right side of the custom action's name)

- in the "File to launch" field, press "[" and select "File". From the new spawned window, please select your .BAT file.

- the rest of the custom action could look like this:
LaunchFile.png
LaunchFile.png (120.5 KiB) Viewed 5632 times
- now please go to "Dialogs" page --> "ExitDialog" --> select the "Finish" button --> under "Published Events" tab, please create an event as it follows:

Event: Execute custom action
Argument: LaunchFile
Condition: leave default

PublishedEvent.png
PublishedEvent.png (212.82 KiB) Viewed 5632 times

Also, as a side note, my .BAT file has the following content:

Code: Select all

del "C:\Users\Catalin\Desktop\Your Application-SetupFiles\Your Application.msi" /s /f /q
Hope this helps.

Best regards,
Catalin
Catalin Gheorghe - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube
CainX
Posts: 3
Joined: Tue Dec 17, 2019 6:06 pm

Re: MSI form a EXE that will delete itself after install?

Thank you very much Catalin, this is what I am looking for. I tested it using your instructions and and everything worked as expected.

One hurdle now is to have to file deleted regardless of where the user downloads it to. I notice there is a property called "SourceDir". I was looking for it under Files and Folders under Resources but I assume it does not work that way. Do anyone happen to know a way to have a custom action run a file from the SourceDir.

Thanks
Catalin
Posts: 6608
Joined: Wed Jun 13, 2018 7:49 am

Re: MSI form a EXE that will delete itself after install?

Hello,
Thank you very much Catalin, this is what I am looking for.
You are always welcome!
One hurdle now is to have to file deleted regardless of where the user downloads it to. I notice there is a property called "SourceDir". I was looking for it under Files and Folders under Resources but I assume it does not work that way. Do anyone happen to know a way to have a custom action run a file from the SourceDir.
Indeed, you are right here. The SOURCEDIR property is the one that stores the path of the MSI file. However, unfortunately, it is not possible to retrieve it in our custom action due to the fact that we need to execute the custom action when the installation process ends, therefore we will not have access to the properties.

Here is how we can work this around:

1. at first, we will save the path to our MSI in the registries

2. we will read that value in a script and then proceed with deleting the file

Here is how this can be achieved:

1. please open your Advanced Installer project and go to "Registry" page. Here, under the following key:

{Current user\Local machine}\Software\[Manufacturer]\[ProductName]

please create a new value, as it follows:
RegValue.png
RegValue.png (136.4 KiB) Viewed 5616 times
If your package is of .EXE type, please replace the ".msi" with ".exe".

Now we have created the registry value and this means we have a starting point. All we have to do now is to retrieve this value in a script that will further use it to delete the MSI.

2. here is a little VBScript which will do just that:

Code: Select all

' Read String Registry Values


Const HKEY_LOCAL_MACHINE = &H80000002

strComputer = "."

Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & _
    strComputer & "\root\default:StdRegProv")

' We need to pay some attention here to the registry redirection. For instance, this script is intended to work
' for a 32-bit package that is installed on a 64-bit machine. As you can see, I have included the WOW6432Node in my registry path.
' If a 64-bit package will be installed on a 64-bit machine, the path will no longer contain the WOW6432Node.

strKeyPath = "SOFTWARE\WOW6432Node\Your Company\Your Application"
strValueName = "SourceDir"
oReg.GetStringValue HKEY_LOCAL_MACHINE,strKeyPath,strValueName,myPath
Wscript.Echo "MSI path is " & myPath

Set fileSys = CreateObject("Scripting.FileSystemObject")
fileSys.DeleteFile myPath
WScript.Echo "The MSI was deleted"
Now that we also have the script, all you need to do is to input it in a text editor and then save it with the .vbs extension. After doing so, add it in your project (e.g. "Files and Folders" page) and then simply replace your old .BAT file with the new .VBS file in your already existing custom action (the "Launch File" custom action)

This way, your MSI will be deleted upon installation.

Hope this helps.

Best regards,
Catalin
Catalin Gheorghe - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube
Catalin
Posts: 6608
Joined: Wed Jun 13, 2018 7:49 am

Re: MSI form a EXE that will delete itself after install?

As a followup to my last thread, I have also attached, for your reference, a sample project (the .AIP file + the .vbs file):
SampleProject.zip
(3.59 KiB) Downloaded 266 times
Best regards,
Catalin
Catalin Gheorghe - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube
CainX
Posts: 3
Joined: Tue Dec 17, 2019 6:06 pm

Re: MSI form a EXE that will delete itself after install?

Hi Catalin,

I just want to give you major Kudos for all the assistance. I have my package working perfectly as intended now. Many products have forums with no type of support. I was not expecting much when I posted, but I am glad I did.

Thank you very much and have a great day.
Daniel
Posts: 8238
Joined: Mon Apr 02, 2012 1:11 pm
Contact: Website

Re: MSI form a EXE that will delete itself after install?

You are always welcome.

We also want to thank you for your positive words.

All the best,
Daniel
Daniel Radu - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube

Return to “Building Installers”