var sc = new System.ServiceProcess.ServiceController("ELSRegressionService");
Its working fine, when logged in with Administrator credentials. If I login with other user credentials, it throws exception, "Cannot open Servicexxx service on computer 'COMPUTER_NAME'"
I would like to ask for credentials before the user tries to start service. So please guide me to check for credentials to start windows service programmatically. Thanks in advance
If you need administrator privilege only for starting the service, you could delay request for elevation till you need it. This can be done by starting a new process and setting ProcessStartInfo.Verb[^] to runas. This new process can execute the code to start/stop the service. You need the new process because you can't change elevation levels of the current process while it is running.