// C# //
...
System.ServiceProcess.ServiceController Service;
if (this.m_MachineName!="")
{Service = new ServiceController(this.m_ServiceName, this.m_MachineName ) ;}
else
{Service = new ServiceController(this.m_ServiceName ) ;}
...
public bool RestartServervice(WindowsPrincipal User,
bool ToDebug,
out string ErrorInfo)
{
try
{
ErrorInfo ="";
if (this.StopService(User, ToDebug, out ErrorInfo))
{
if (this.StartService(User, ToDebug, out ErrorInfo))
{return true;}
else{return false;}
}
else
{return false;}
}
catch (Exception ex_restart_service)
{
ErrorInfo = "Restart Service [" + this.m_ServiceName + "] [" + ex_restart_service.Message + "]";
return false;
}
}
Where