C# ServiceController Run as Administrator on demand RRS feed

  • Question

  • I have written a C# program that normally will NOT be run as an administrator.

    I have a method using the ServiceController class which is to stop and start a Windows service.

    Is there a way to run this method as an Administrator without actually running the main program as Administrator?

    Tuesday, May 6, 2014 3:32 AM


  • Hi, you can try this:

    private void StartService(string name)
        var process = new Process();
        process.StartInfo.FileName = "net";
        process.StartInfo.Arguments = "start " + name;
        process.StartInfo.Verb = "runas";//run as administrator
    above method run net.exe as Administrator to start service, if you don't like to see the console of net.exe, you can write a small application which use ServiceController to start service and you can run the small application in above StartService method. 

    Tuesday, May 6, 2014 4:18 AM