Reputation: 17293
I am trying to create an MSI installer/uninstaller for my Windows project, consisting of a service, a couple of user-mode exes/dlls and some data files. I was able to use Visual Studio 2010 to compile an MSI package using its Setup Project
. It works fine for installation, but uninstallation requires some additional steps before files are actually removed along with the registry settings.
So I was wondering, is there any way I can run a script (C#, or WSH JScript) before removing files/registry settings?
Upvotes: 1
Views: 2210
Reputation: 3674
Yes, you can add as well scripts (VBS or JScript) to an MSI as C# or C++ custom actions in compiled MSI enabled Dlls, you can call .exe files, etc. There is a table called CustomAction and the Custom actions can be sequenced with the sequence tables, the most important are InstallExecuteSequence and InstallUISequence.
Working with custom actions is not so an easy task I think. If it is possible for you to ask experts, I would consider it.
Most times, when you want to add a custom action for uninstalling resources, there is maybe something wrong with your MSI. 4 of 5 custom actions one wants to add, are not necessary but can be replaced with correct MSI table entries.
Generally, I don't recommend using Visual Studio installer, because it gives you not very much control, and it is easy to make things wrong, especially for upgrading and more complicated task.
But if you still want to add a custom action here is some basic idea: For example for starting a VB script you can add a custom action of type 38. Choose a name in the "Action" column, let the "Source" columns empty, and type the VB script code in the "Target" column: E.g. with something like that you have an VB "interface" to the MSI properties like the newly invented "MYDIR_EXISTS" here.
on Error Resume Next
set filobj = Createobject( "Scripting.FileSystemObject" )
If filobj.FolderExists("C:\MyDir") Then Session.Property("MYDIR_EXISTS") = "True"
...
If you work with Visual Studio Installer you could consider adding the custom actions with a transform afterwards. Again this needs some MSI knowledge.
Me, personally, I would not work with script files for distributed setups, only if the setup is an infrastructural one for the same company. But it is a starting point. Calling an compiled .exe with Custom Action type 34 or 50 would be an alternative.
Upvotes: 2