I have some code to start my application services, which I call before the start of my automated test cases. But I have to run either visual studio or test agent as administrator. Is there any other way to run it?
//My method
//Code to start stopped Pfx services
ServiceController PfxService = new ServiceController();
string[] PfxServiceList = { "******.SocketService", "******.WcfServices", "MSSQL*****" };
foreach (string ServiceName in PfxServiceList)
{
PfxService.ServiceName = ServiceName;
string ServiceStatus = PfxService.Status.ToString();
if (ServiceStatus == "Stopped")
{
PfxService.Start();
PfxService.WaitForStatus(ServiceControllerStatus.Running);
Playback.Wait(2000);
}
}