I am currently working on a Windows Forms application that, for some functionality, needs admin privileges to modify an .ini file for a legacy application that is referenced. However, it is known that no all users will have admin rights.
My current idea is to add an app.manifest file to the solution and set the requestedExecutionLevel to highestAvailable in order to request admin rights if possible and otherwise run at the default security. app.manifest settings for reference:
<requestedPrivileges xmlns="urn:schemas-microsoft-com:asm.v3">
<!-- UAC Manifest Options
If you want to change the Windows User Account Control level replace the
requestedExecutionLevel node with one of the following.
<requestedExecutionLevel level="asInvoker" uiAccess="false" />
<requestedExecutionLevel level="requireAdministrator" uiAccess="false" />
<requestedExecutionLevel level="highestAvailable" uiAccess="false" />
Specifying requestedExecutionLevel element will disable file and registry virtualization.
Remove this element if your application requires this virtualization for backwards
compatibility.
-->
<requestedExecutionLevel level="highestAvailable" uiAccess="false" />
</requestedPrivileges>
My question is, is it then possible to detect the execution level so I can then modify the app's behavior based on if the user has admin access?
Edit: I am looking for a way to check specifically if the the app itself is run at an elevated level as opposed to at a default security if possible. The suggested solution of validating the user's permissions level is a potential/partial solution, but I would much prefer, if possible, to verify the behavior of the app directly as opposed to potential level of the user. Thank you.