PrepAway - Latest Free Exam Questions & Answers

What code should you use?

Domain.com has asked you to develop an application allows administrators to control Windows services dynamically without using the Services MMC.
You start by creating a class named LocalServiceController. You need to add the correct code to the LocalServiceController class to ensure that administrators are
able to start local Windows services.
What code should you use?

PrepAway - Latest Free Exam Questions & Answers

A.
public static bool StartService (string serviceName) {
try {
ServiceBase.Run (serviceName);
return true;
}
catch {
return false;
}
}

B.
public static bool StartService (string serviceName) {
ServiceController controller = new ServiceController (serviceName);
if (controller.Status != ServiceControllerStatus.Running) {
controller.Start ();
return true;
}
else
return false;
}

C.
public static bool StartService (string serviceName) {
ServiceManager manager = new ServiceManager (serviceName);
if (manager.Status != ServiceManagerStatus.Running) {
manager.Start ();
return true;
}
else
return false;
}

D.
public static bool StartService (string serviceName) {
ServiceBase service = new ServiceBase ();
service.ServiceName = serviceName;
if (service.CanStart) {
ServiceBase.Run (service);
return true;
}
else
return false;
}

One Comment on “What code should you use?


Leave a Reply