Admin rights for a single method in C#
To run a single method as admin in C# you can add a PrincipalPermission attribute to your method to demand administrative privileges for its execution, this Allows security actions for PrincipalPermission to be applied to code using declarative security. This class cannot be inherited.Important: Partially trusted code is no longer supported. This attribute has no effect in .NET Core.
Example
[PrincipalPermission(SecurityAction.Demand, Role = @"BUILTIN\Administrators")]
public void MethodToExecuteAsAdmin()
{
/* Method code to be executed as admin here */
}