The link has JScript syntax for the same thing. Use this for your C#Script.
function Test()
{
StopService(".", "TestComplete 7 Service");
Delay(10000);
StartService(".", "TestComplete 7 Service");
}
function StartService(computerName, serviceName)
{
var service = GetService(computerName, serviceName);
if (service == null) {
Log.Warning("The " + serviceName + " service on the " + computerName +
" computer was not found");
}
else
service.StartService();
}
function StopService(computerName, serviceName)
{
var service = GetService(computerName, serviceName);
if (service == null) {
Log.Warning("The " + serviceName + " service on the " + computerName +
" computer was not found");
}
else
service.StopService();
}
function GetService(computerName, serviceName)
{
var wmiService, objectsList, eObjectsList, item, sysID;
wmiService = GetObject("WinMgmts:{impersonationLevel=impersonate}!\\\\" +
computerName + "\\root\\cimv2");
objectsList = wmiService.InstancesOf("Win32_Service");
if (objectsList.Count > 0) {
eObjectsList = new Enumerator(objectsList);
for (; !eObjectsList.atEnd(); eObjectsList.moveNext()) {
item = eObjectsList.item();
if (item.Name == serviceName)
return item;
}
}
return null;
}