Is it possible to install into Program Files with

2019-04-25 18:53发布

问题:

I have an application that will be deployed as MSI package (authored in WiX).

I am deciding whether to specify elevated or limited privileges as required for the installer.

The application does not include anything requiring elevated privileges besides the default install location, which is under Program Files.

Now the problem:

  • If I specify elevated privileges, then the user is prompted by UAC for administrator password during the installation. This is not required and prevents non-admin users from installing.

  • If I specify limited privileges, then the user is presented with a dialog to select install location with Program Files being default. In case they do not change the install location (95 % of end users probably won't), then the installer will fail with a message that they should contact the Administrator or run the application as administrator. If they launch the installer as Administrator then they can install into Program Files without problem - but most of the users won't probably know how to launch an installer as administrator.

I can potentially set the default install location to e.g. C:\Company name\Program\, but this seems nonstandard to me and majority of users will not probably like this (they are probably used to installing into Program Files).

How do you solve this problem with installing applications under limited user accounts?

回答1:

The alternate location you propose, directly off of the C Drive, is likely to also require elevated privileges. Before Windows 7, I would suggest using an early custom action to change your default location for limited installations. Condition it off of the Privileged (or possibly AdminUser) property, verify whether you need to set MSIUSEREALADMINDETECTION for your case, and use something like [LocalAppDataFolder]Company\Product. Unfortunately this approach will result in a package that is difficult to install for all users as you must pre-elevate, and in the limited case they could still select a target location that requires elevation. They must pre-elevate because the package must be marked to not elevate.

If you can target solely Windows 7 and later, you can conditionally set MSIINSTALLPERUSER to override the install location and the elevation requirement, and instead install per-user. In this scenario, the user could be asked whether to install for all users (requires elevation) or just for himself. The package can be marked for elevation, and setting MSIINSTALLPERUSER will override that and skip the UAC prompt.



回答2:

It's probably more important that your software runs with normal user privileges - which I see you've mentioned isn't an issue.

There's nothing wrong in asking for admin rights to install something.

Either, the user will have the details themselves as they are running a limited account for safety reasons or the software will be installed by their company's IT department anyway.



回答3:

Run command prompt(cmd) as administrator.

Then use msiexec command to execute msi file.