Admin rights for a single method

You can add a PrincipalPermission attribute to your method to demand administrative privileges for its execution: [PrincipalPermission(SecurityAction.Demand, Role = @”BUILTIN\Administrators”)] public void MyMethod() { } This is described in more detail in the following article: Security Principles and Local Admin Rights in C# .Net If you are looking for a way to elevate an already … Read more

How to start a new process without administrator privileges from a process with administrator privileges?

What you are trying to achieve cannot be done very easily and is not supported. However, it is possible using a modicum of hacking. Aaron Margosis wrote an article describing one technique. To quote the pertinent section, you will need to carry out these steps: Enable the SeIncreaseQuotaPrivilege in your current token Get an HWND … Read more

Start / Stop a Windows Service from a non-Administrator user account

Below I have put together everything I learned about Starting/Stopping a Windows Service from a non-Admin user account, if anyone needs to know. Primarily, there are two ways in which to Start / Stop a Windows Service. 1. Directly accessing the service through logon Windows user account. 2. Accessing the service through IIS using Network … Read more

How do I force my .NET application to run as administrator?

You’ll want to modify the manifest that gets embedded in the program. This works on Visual Studio 2008 and higher: Project + Add New Item, select “Application Manifest File”. Change the <requestedExecutionLevel> element to: <requestedExecutionLevel level=”requireAdministrator” uiAccess=”false” /> The user gets the UAC prompt when they start the program. Use wisely; their patience can wear out quickly.