Which code segment should you use?

You need to write a code segment that performs the following tasks: ? Retrieves the name of each paused service. ?
Passes the name to the Add method of Collection1.
Which code segment should you use?

You need to write a code segment that performs the following tasks: ? Retrieves the name of each paused service. ?
Passes the name to the Add method of Collection1.
Which code segment should you use?

A.
ManagementObjectSearcher searcher = new ManagementObjectSearcher( “Select * from Win32_service where State = ‘Paused'”);
foreach (ManagementObject svc in searcher.Get()) {
Collection1.Add(svc[“DisplayName”]);
}

B.
ManagementObjectSearcher searcher = new ManagementObjectSearcher( “Select * from Win32_service”, “State = ‘Paused'”);
foreach (ManagementObject svc in searcher.Get()) {
Collection1.Add(svc[“DisplayName”]);
}

C.
ManagementObjectSearcher searcher = new ManagementObjectSearcher( “Select * from Win32_service”);
foreach (ManagementObject svc in searcher.Get()) {
if ((string) svc[“State”] == “‘Paused'”) {
Collection1.Add(svc[“DisplayName”]);
}
}

D.
ManagementObjectSearcher searcher = new ManagementObjectSearcher();
searcher.Scope = new ManagementScope(Win32_service”);
foreach (ManagementObject svc in searcher.Get()) {
if ((string)svc[“State”] == “Paused”) {
Collection1.Add(svc[“DisplayName”]);
}
}

Explanation:
Use the ManagmentObjectSearcher to search for all services with a paused state.
Iterate over the returned collection and add the display name to Collection1.
B The constructor is invoked incorrectly.
C & D the query is incorrect. The searcher does not restrict to paused services.



Leave a Reply 0

Your email address will not be published. Required fields are marked *