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 (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