Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Administrator-Privilegs for a Single Method

Tags:

c#

security

Im Currently working on an ApplicationLauncher / Autoupdater. So for installing/updating an app to "Program Files", i need to request Administrator rights.

Well, since the Updater only needs to write something if new Versions are found, i tried to only request the privilegs, if a new Version is found.

The updater is executed everytime, before the application launches, so asking "everytime" for Adminrights is no solution...

I searched a lot, and found the following:

[PrincipalPermission(SecurityAction.Demand, Role = @"Administrators")]
    private void InstallOrUpdate(AppItem appItem)

but wenn i try to this, the updater throws a SecurityException...

Request for principal permission failed.

What am i doing wrong?

Best regards, dognose

like image 992
dognose Avatar asked Jan 31 '11 16:01

dognose


People also ask

What are the administrator privileges?

An administrator is someone who can make changes on a computer that will affect other users of the computer. Administrators can change security settings, install software and hardware, access all files on the computer, and make changes to other user accounts.

How many ways can administrator root privileges on a machine?

You can obtain root privileges via two methods: Log in as root from the console. Log in as a normal user, then assert root privileges using the su command.

What are administrator privileges when trying to install a download?

Only certain trusted users should be allowed to have administrative privileges. This prevents other users from messing with the computer and doing things like uninstalling applications that you need, installing applications that you don't want, or changing important files. This is useful from a security standpoint.


2 Answers

You cannot elevate permissions for the application once it's running. In order to request the Administrators role, it will need to be done at startup time of the executable.

Your best option would be to have your updater either fire a different executable to do the InstallOrUpdate, or to re-run itself (with a different command line argument, potentially) with a request for elevated permissions at that point.

like image 88
Reed Copsey Avatar answered Sep 21 '22 13:09

Reed Copsey


UAC elevation is per-process, i.e. the process as a whole is elevated, not per single method. The best course of action, would be to create a specific action process that requires elevated privileges, and launch that process from your updater when it actually needs to do some work. This might help.

like image 36
Matthew Abbott Avatar answered Sep 23 '22 13:09

Matthew Abbott