Which code segment should you use?

You are testing a method that examines a running process.
This method returns an ArrayList containing the name and full path of all modules that are loaded by the process.
You need to list the modules loaded by a process named C:TestAppsProcess1.exe.
Which code segment should you use?

You are testing a method that examines a running process.
This method returns an ArrayList containing the name and full path of all modules that are loaded by the process.
You need to list the modules loaded by a process named C:TestAppsProcess1.exe.
Which code segment should you use?

A.
ArrayList ar = new ArrayList();
Process[] procs;
ProcessModuleCollection module;
procs = Process.GetProcesses(@”Process1″);
if (procs.Length > 0) {
module = procs[0].Modules;
foreach (ProcessModule mod in modules) {
ar.Add(mod.ModuleName);
}
}

B.
ArrayList ar = new ArrayList();
Process[] procs;
ProcessModuleCollection module;
procs = Process.GetProcesses(“C:TestAppsProcess1.exe”);
if (procs.Length > 0) {
module = procs[0].Modules;
foreach (ProcessModule mod in modules) {
ar.Add(mod.ModuleName);
}
}

C.
ArrayList ar = new ArrayList();
Process[] procs;
ProcessModuleCollection module;
procs = Process.GetProcessesByName(@”Process1″);
if (procs.Length > 0) {
module = procs[0].Modules;
foreach (ProcessModule mod in modules) {
ar.Add(mod.FileName);
}
}

D.
ArrayList ar = new ArrayList();
Process[] procs;
ProcessModuleCollection module;
procs = Process.GetProcessesByName(@”C:TestAppsProcess1.exe”);
if (procs.Length > 0) {
module = procs[0].Modules;
foreach (ProcessModule mod in modules) {
ar.Add(mod.FileName);
}
}

Explanation:
Process.GetProcessesByName() should be used to return all the processes that match a process name.
The modules collection exposes all the modules loaded by the process and can be added to an ArrayList.
A & B GetProcesses() accepts a computer name for retrieving the processes on a remote computer.
GetProcessesByName() should be used to return processes by their name. D the path of the process is not part of the process name.
�Process.GetProcessesByName(“nurName”);



Leave a Reply 0

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