I need to run executable for custom setup/tear down, after install and before uninstall. It needs to run with elevated privileges. How to do this correctly?
问题:
回答1:
Have a look at this blog at the section How to author custom actions that require administrative privileges
An other link that really explains all the types of Custom Actions. The CustomAction Element in Wix.
This should help you a bit more.
After looking at your Solution you seem to be doing a Type 18 CustomAction, here I pasted the contents of the previous Blog for those types:
Custom Action Type 18 Calls an executable which is installed with the application during current session. The Source column in the CustomAction table contains the key to the record in the File table.
The Target column in the CustomAction table contains the command line string for the executable. All return processing, execution scheduling, and in-script execution options apply.
Because file is installed with the application, there are sequencing restrictions on custom action Type 18:
If the source file is not already installed on the computer:
Custom action must be sequenced after CostFinalize action because only after this action path to the file can be resolved.
If the source file is not already installed on the computer:
Deferred custom actions of this type must be sequenced after the InstallFiles action.
Non-deferred custom actions of this type must be sequenced after the InstallFinalize action.
Entry point to the custom action receives the handle to the installation session. During execution of deferred custom action, session may no longer exist. To get the value of properties use CustomActionData property.
Here is how to add Type 18 custom action in Wix:
<Directory Id="TARGETDIR" Name="SourceDir">
<Component Id="Component1"
Guid="*">
<File Id="MyCA" Name="MyCA.exe" />
</Component>
</Directory>
<CustomAction Id="DoSomething"
FileKey="MyCA"
ExeCommand="-switch"
Execute="deferred"
Return="check"
HideTarget="no"
Impersonate="no" />
<InstallExecuteSequence>
<Custom Action="DoSomething" Before="InstallFinalize" />
</InstallExecuteSequence>
First, we add MyCA.exe to the File table.
We also add a custom action of Type 18 to the CustomAction table. FileKey attribute points to the element with the custom action dll. ExeCommand attribute specifies the command line string for the executable.
The last thing to do is to schedule our custom action in all required sequence tables.
This should help you out, sort what is missing, but I strongly suggest that you look at all the types of Custom Actions that will help you later on when making more installers
回答2:
So, the final solution was like this:
<CustomAction Id="Install" Directory="APPLICATIONROOTDIRECTORY"
Execute="deferred" Impersonate="no" Return="ignore"
ExeCommand="[APPLICATIONROOTDIRECTORY]MyExeName.exe -install" />
<CustomAction Id="Uninstall" Directory="APPLICATIONROOTDIRECTORY"
Execute="deferred" Impersonate="no" Return="ignore"
ExeCommand="[APPLICATIONROOTDIRECTORY]MyExeName.exe -uninstall" />
<InstallExecuteSequence>
<Custom Action='Install' After='InstallFiles' >
$ProductComponent = 3
</Custom>
<Custom Action='Uninstall' After='InstallInitialize' >
?ProductComponent = 3
</Custom>
</InstallExecuteSequence>
Any advise to improve it?
回答3:
You could add 'NOT REMOVE' for Install & Repair Sequence. And 'Installed AND (REMOVE = "ALL")' only for UnInstall sequence.
<InstallExecuteSequence>
<Custom Action='Install' After='InstallFiles' >
NOT REMOVE
</Custom>
<Custom Action='Uninstall' After='InstallFiles' >
Installed AND (REMOVE = "ALL")
</Custom>
</InstallExecuteSequence>