Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(875)

Unified Diff: visual_studio/NativeClientVSAddIn/NativeClientVSAddIn/ProcessSearcher.cs

Issue 10758009: Native Client Visual Studio Add-in (Closed) Base URL: https://nativeclient-sdk.googlecode.com/svn/trunk/src
Patch Set: Style Fixed Created 8 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: visual_studio/NativeClientVSAddIn/NativeClientVSAddIn/ProcessSearcher.cs
diff --git a/visual_studio/NativeClientVSAddIn/NativeClientVSAddIn/ProcessSearcher.cs b/visual_studio/NativeClientVSAddIn/NativeClientVSAddIn/ProcessSearcher.cs
new file mode 100644
index 0000000000000000000000000000000000000000..e7f6583fcfbbab46bd192fed932778737cb8d50e
--- /dev/null
+++ b/visual_studio/NativeClientVSAddIn/NativeClientVSAddIn/ProcessSearcher.cs
@@ -0,0 +1,67 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Management;
+using System.Text;
+
+namespace NativeClientVSAddIn
+{
+ /// <summary>
+ /// Queries the system for the list of running processes
+ /// </summary>
+ public class ProcessSearcher : IProcessSearcher
+ {
+ /// <summary>
+ /// Returns results of a process search subject to given constraints
+ /// </summary>
+ /// <param name="constraints">Constraints in the form 'field=target'</param>
+ /// <returns>List of matching processes</returns>
+ public List<ProcessInfo> GetResults(String constraints)
+ {
+ var results = new List<ProcessInfo>();
+ String fields = "ProcessID, ParentProcessID, CommandLine, Name, CreationDate";
+ String query = String.Format("select {0} from Win32_Process where {1}", fields, constraints);
Petr Hosek 2012/07/12 00:25:46 I would rather go for LINQ here to make the query
tysand 2012/07/12 23:56:15 Neat. Done. On 2012/07/12 00:25:46, phosek1 wrote:
+ using (ManagementObjectSearcher searcher = new ManagementObjectSearcher(query))
noelallen1 2012/07/11 22:16:46 Why using scope here, but not in other locations?
tysand 2012/07/12 23:56:15 Because ManagementObjectCollection and ManagementO
+ {
+ using (ManagementObjectCollection result = searcher.Get())
+ {
+ foreach (ManagementObject process in result)
+ {
+ results.Add(new ProcessInfo(
+ id: (uint)process["ProcessID"],
+ parentId: (uint)process["ParentProcessID"],
+ creationDate: process["CreationDate"] as String,
+ commandLine: process["CommandLine"] as String,
+ name: process["Name"] as String));
+ }
+ }
+ }
+
+ return results;
+ }
+
+ /// <summary>
+ /// Searches the system for all processes of a given name
+ /// </summary>
+ /// <param name="name">Name to search for</param>
+ /// <returns>List of matching processes</returns>
+ public List<ProcessInfo> GetResultsByName(String name)
+ {
+ return GetResults(String.Format("Name='{0}'", name));
Petr Hosek 2012/07/12 00:25:46 Using the change above, this will now look as foll
tysand 2012/07/12 23:56:15 Done.
+ }
+
+ /// <summary>
+ /// Searches the system for all processes of a given process ID
+ /// </summary>
+ /// <param name="procID">ID to search for</param>
+ /// <returns>List of matching processes</returns>
+ public List<ProcessInfo> GetResultsByID(uint procID)
+ {
+ return GetResults(String.Format("ProcessID='{0}'", procID));
Petr Hosek 2012/07/12 00:25:46 The same here: return GetResults(m => m.Propertie
tysand 2012/07/12 23:56:15 Done.
+ }
+ }
+}

Powered by Google App Engine
This is Rietveld 408576698