Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
746 views
in Technique[技术] by (71.8m points)

wix - How to run custom executable with elevated privileges?

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...