Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Run part of a c# program with admin privileges

Is there a way to request elevated privileges from the os, for "just a part" of a c# program?

I'm writing a bunch of integrationtests using NUnit. One of the things I'm testing is if the application under test correctly connects to port 843. The test opens a listening socket at port 843, and then throws all sorts of responses to the application under test, and verifies if the application behaves correctly.

Opening a listening socket on port 843 requires admin privileges however.

I'd like to find the least intrusive way to be able to run this test. I could run the entire NUnit suite as root/admin, but that would make a lot of stuff run as root, that really doesn't need to be ran as root, which I'd like to prevent.

like image 988
Lucas Meijer Avatar asked Feb 16 '10 09:02

Lucas Meijer


People also ask

What are AC parts called?

There are four major components of an air conditioning system. They are the evaporator, condenser, compressor, and expansion valve. Each of these air conditioner components functions in sync with each other and has a specific job to do – to keep your air conditioner running like a well-oiled machine.

What are the 4 main parts of an air conditioner?

In reality, the average air conditioner can be broken down into four main components: the evaporator coil, compressor, condenser coil, and expansion valve.

What part of the car runs the AC?

Compressor The four main functions that your vehicle's compressor carries out include: Pressurizing the refrigerant to cool the air. Sensing temperature changes inside and outside your car.

What runs off of AC?

AC is also the more popular current when it comes to powering electric motors, a device that converts electric energy into mechanical energy. Some household appliances that we use that rely on this are, but aren't limited to: refrigerators, dishwashers, garbage disposals, and toasters.


1 Answers

If required below code would help you to find out if the current logged in user is admin or not:

using System;
using System.Security.Principal; 

class Test
{
    public static void Main()
    {
        if (new WindowsPrincipal(WindowsIdentity.GetCurrent()).IsInRole(WindowsBuiltInRole.Administrator))
        {
            Console.WriteLine("I am an admin.");
        }
    }
}
like image 102
Neo Avatar answered Oct 08 '22 22:10

Neo