WiX installer should always run as administrator

前端 未结 3 1964
庸人自扰
庸人自扰 2020-12-31 05:51

I developed a custom installer with WiX for a .NET WPF application. It works fine if I right-click and run as administrator, however when running without, some components fa

相关标签:
3条回答
  • 2020-12-31 06:12

    For me I was supposed to run a registry command to delete a system environment variable via the CustomAction WiX element, which required administrator privileges.

    Using CustomAction → Impersonate="no" worked for me as mentioned in post https://stackoverflow.com/a/8657472/3205679.

    WiX Custom Action code:

    <CustomAction Id = "Uninstall_MYSYSENV"
                  Directory  = "INSTALLFOLDER"
                  ExeCommand = 'cmd.exe /c &quot;reg delete       "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session    Manager\Environment" /v MYSYSENV /f&quot;'
                  Execute    = "deferred"
                  Impersonate= "no"
                  Return     = "asyncNoWait"
                  />
    
    <InstallExecuteSequence>
          <Custom Action="Uninstall_MYSYSENV"
                  After="InstallInitialize">Installed AND NOT UPGRADINGPRODUCTCODE</Custom>
    </InstallExecuteSequence>
    
    0 讨论(0)
  • 2020-12-31 06:23

    Add this to your package element

    <Property Id="ALLUSERS" Value="1" />    <!--equals to install="permachine" at package element but this element depricated -->
    <Property Id="MSIUSEREALADMINDETECTION" Value="1" /> 
    
    <Condition Message="Please Run as Administrator.">
          Privileged
    </Condition>
    

    Then creating a simple sfx archive file for msi file with Winrar and these options:

    • Setup tab > Run after execution input: your msi file name

    • Advanced tab > Mark Request Administrative access option checkbox

    0 讨论(0)
  • 2020-12-31 06:37

    I think if you just add

    <Property Id="MSIUSEREALADMINDETECTION" Value="1" />
    

    it should solve the problem. Let me know if not and I can do some more checking.

    0 讨论(0)
提交回复
热议问题