1

I have a windows forms app developed in c# and have created a setup file for it. .Net Framework used is 3.0.

Now, setup should force for admin rights for installation and then proceed else not.

I found articles on creating manifest file which works fine but when program is launched after installation it again asks for admin rights which is not i want.

And this prompt should also work on Windows XP SP 1 and above OS.

Ronak
  • 187
  • 2
  • 17
  • Does this answer your question? [How do I force my .NET application to run as administrator?](https://stackoverflow.com/questions/2818179/how-do-i-force-my-net-application-to-run-as-administrator) – Hasan Feb 20 '20 at 06:18
  • @Clint - Actually i don't want to run GUI application with admin rights. But if admin allows to install the app then app should get installed and hence while installing setup we want to prompt for admin rights. – Ronak Feb 20 '20 at 10:33
  • @Ronak, while installing any MSI/WindowsInstaller will prompt for admin rights, the setup file is nothing but a collection of assemblies,dlls,files, you're app needs to function. But after installation is your GUI app performing tasks that require elevated privilege ? – Clint Feb 20 '20 at 10:47
  • @SMMahmudulHasan - Will app.manifest file work for Windows XP as well? I mean Windows XP and later OS. – Ronak Feb 20 '20 at 16:56
  • @Ronak is your question about enabling setup file to throw UAC prompt ? – Clint Feb 21 '20 at 03:33
  • @Clint - Yes excatly, setup file should prompt. So that only admin user can install the app. – Ronak Feb 21 '20 at 04:52
  • 1
    1) Right Click your Setup Project, View->Launch Conditions. 2) Right click on Launch Conditions, and add a new Condition in your Launch Conditions. 3) Right click the Condition, choose Properties Window. 4) Set Condition to AdminUser. 5) Build and install. – Clint Feb 21 '20 at 06:08

1 Answers1

0

To prompt Installer to invoke the UAC prompt to the user you can do the following:

  • Right click your Setup Project > View > Launch Conditions.
  • Right click Launch Conditions > Add a new Condition in your Launch Conditions.
  • Right click the Condition, choose Properties Window.
  • Set Condition to AdminUser. (You can also try setting Privileged property)
  • Build and install

OR

  Edit your .vdproj, change requiresElevation attribute to true

"MsiBootstrapper"
{

    "RequiresElevation" = "11:TRUE"
}
Clint
  • 6,011
  • 1
  • 21
  • 28
  • 1
    I will try solution provided by you. I also found another way by adding app.manifest file and setting requestedExecutionLevel to requireAdministrator like below. – Ronak Feb 21 '20 at 10:00
  • yes, you are doing the above on your WinForm project or Installer Project ? – Clint Feb 21 '20 at 10:09
  • It is in win forms project. – Ronak Feb 21 '20 at 10:16
  • yes you can do that on winforms project, then your winforms app will throw the UAC prompt, instead of the Installer. – Clint Feb 21 '20 at 10:21
  • @Ronak, you can let me know if you need help – Clint Feb 21 '20 at 10:55
  • @Ronak, you're welcome, if you think the answer has helped out, you can accept the answer by clicking the green tick mark ;) – Clint Feb 27 '20 at 03:34