How to make the setup.exe from a VS2010 Setup Project ask for Admin Privileges?

I have a problem which I guessed would be really simple to solve... but duh.

I'm deploying a .NET application with VS2010. I have a C# Windows Forms project and a Deployment Project. I need the installer to run with admin privileges because the app is installed for all users and an entry to the registry is made.

When starting the setup.exe I'm not prompted for privilege elevation. The installer will just start and suggest to install to Program Files (x86) which is good. After clicking next the installer runs and finished with a success message. Which is basically a lie because it did not successfully install. Instead it puts the apps exe directly to C:\.

How can I make the installer ask for admin privileges. Or do I have to rely on my customer to right click the setup and select "Run as Admin" which is very error prone?

Clarifications about my setup:

  • In the File System view of the setup project I added (among other things) "Primary Output from project01 (Active)" and "Build Outputs from project01 (Active) to "Application Folder". I also added a shortcut to "Primary Output" into "User's Programs Menu\CompanyName\ProgramName".
  • In the Registry View I added an entry to HKEY_CLASSES_ROOT because I need to register an url handler.

I also modified the setup's settings: I set InstallAllUsers to True because it is supposed to do so.

When I build and start the setup.exe by double clicking (or by selecting Install from the project's context menu) I always get the same result: The installer runs without asking for admin privileges, ask for an install location (which I leave at the default C:\Program Files(x86)\Company\ProgramName) and then procedes after clicking Next. As a result, the exe is put directly in C:\ and the shortcut created of course points into Nirvana.

If I run the setup.exe manually as Administrator things work fine. But this cannot seriously be the way to go.

So how can I tell the setup to always run as Admin?

Answers


I think this is a perfectly valid question, is a real problem, and has an actual explanation.

I recently ran across this problem. In my case, the cause is that the AlwaysInstallElevated policy was set on the computer through GPO. The policy was set to 1 in the per-machine policy and 0 in the per-user policy. These policies can be manually set to reproduce the effect it has on MSI installers

Using msexec /log install.log /i Deploy.msi, I had a setup log and there were strings in it like this:

MSI (s) (A4:8C) [13:00:42:885]: Ignoring disallowed property TARGETDIR
MSI (s) (A4:8C) [13:00:42:885]: Ignoring disallowed property VSDNETURLMSG
MSI (s) (A4:8C) [13:00:42:885]: Ignoring disallowed property VSDNETMSG

It seems that Visual Studio does not set the SecureCustomProperties in the MSI correctly and post processing of some sort is needed. I think that moving to WiX may be a better long term solution instead.

A blog post on MSDN is what I found that helped me find the root cause to this problem.


I've come across the same issue as you, and have found a good enough solution for it. So it might work for you too. The solution is documented here:

VS2010 Setup Project - Run As Administrator

I will re-iterate the solution briefly here. Basically, you need to manually edit the setup project file (.vdproj) and the following property to TRUE:

"MsiBootstrapper"
{
    ...
    "RequiresElevation" = "11:TRUE"
}

When starting the setup.exe I'm not prompted for privilege elevation.

This is the normal behavior. The boostrapper doesn't need elevation.

Which is basically a lie because it did not successfully install. Instead it puts the apps exe directly to C:.

So it did install your application, but in the wrong location. This is not related to elevation. In the File System editor in your setup project where did you add your application files? Did you add them in "Application Folder"?

How can I make the installer ask for admin privileges.

A MSI package installed for all users automatically prompts for elevation when clicking Install button. If it doesn't elevate automatically and installs in a per-machine location (like C:), the installation fails and nothing is copied on the target machine.


Need Your Help

Button being made as an image to execute Javascript random generator

javascript forms function button

Here is my code. I am trying to make a random game button, and I want to add an image instead of the button, but when I change it, the random game element no longer works. Any help would be appreci...

What should I put in my down function when truncate a table in Laravel migration?

php laravel laravel-5

I'm trying to write a migration script to truncate my vistors table.