3

I have project written in C#. I create install project for this project, and I really want that this setup can run only if user has administrative rights. How I can do this?

I tried to add "Launch Condition" with condition = AdminUser, then I build my setup project, but installer can be run from user without admin rights.

Mat
  • 202,337
  • 40
  • 393
  • 406
  • 1
    That's unclear with UAC in the mix. Windows automatically elevates and prompts for permission, purely based on the name of the EXE (setup, upgrade, etc). – Hans Passant Jan 28 '12 at 13:06
  • @HansPassant, That might not be applicable if either you rename the file, or if you run it under windows server 2005, XP, or any other OS that does not have UAC – Ivaylo Slavov Jan 28 '12 at 14:41
  • 2
    Right, my point. Renaming the .exe is the first thing to try. Documenting the OS and the user account's group membership is required to get a decent answer. – Hans Passant Jan 28 '12 at 14:46
  • What's the point? Why do you need your setup to run only with administrative rights? So you can perform action X, which requires admin rights? Fine, then just try to perform action X. If it works, they have admin rights. If not, then they don't, and the setup fails. – Cody Gray - on strike Jan 30 '12 at 08:06
  • @CodyGray - What is the point? I have noticed that if my MSI wants to install in **Program Files**, but the current user does not have permission to write there, the installer will install to **C:\** root, even though the path was specified, and the unelevated user also has no special permission to write there. Most annoying and not what was intended. – Jesse Chisholm Apr 29 '13 at 16:20

1 Answers1

1

AdminUser and Privileged properties can be used to detect Administrator privileges on older Windows versions.

However, on Vista and Windows 7 any user can become an Administrator through elevation (UAC). So you cannot detect if the current user is an Administrator or not.

The most you can do is write a custom action which detects what permissions are assigned to the current user and try to determine if he is an Administrator based on that. But this is rarely worth the effort.

Cosmin
  • 21,216
  • 5
  • 45
  • 60