I'm looking for correct way to allow elevating privileges for selected operations.
Something similar many products offer.
For example if you have UAC turned on and you are using Total Commander (running with basic privileges) when browsing restricted folders you will get:
If you push As Administrator
you will get common User Access Control dialog asking if you want to grant the process required permissions. Is it something similar possible in .NET application (even with Win32 support)?
I'm not looking for solution which will demand running the main process as administrator.
Net App To Run As Administrator. Go to Visual Studio Solution Explorer, right-click the project and select Add >> New Item…. In the Add New Item window, select Application Manifest File and press Add.
Run Visual Studio as an administratorOpen the Start menu, and scroll to Visual Studio. From the right-click or context menu of Visual Studio 2019 or Visual Studio 2022, select More > Run as administrator. When Visual Studio starts, (Administrator) appears after the product name in the title bar.
Start context menu Open Start. Right-click the app (anywhere on the menu). Select the More submenu, and click the Run as administrator option.
You're going to have to factor the target operation functionality into a separate component that will be run elevated. This can be either an executable that requires elevation or a COM component (which could presumably be a COM wrapper for a .NET component). Details are available at http://msdn.microsoft.com/en-us/library/bb756990.aspx, with the When to Add the Shield Icon to Your Application's User Interface being particularly pertinent.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With