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

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: 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..8c4e50fa2f56b1239292fe8442f56a7e03af9fd8
--- /dev/null
+++ b/visual_studio/NativeClientVSAddIn/NativeClientVSAddIn/ProcessSearcher.cs
@@ -0,0 +1,51 @@
+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>
+ class ProcessSearcher : IProcessSearcher
+ {
+ public ProcessSearcher()
Petr Hosek 2012/07/10 05:37:21 Default constructor is generated automatically.
tysand 2012/07/11 05:23:46 Done.
+ {
+ }
+
+ public List<ProcessInfo> GetResults(string constraints)
+ {
+ List<ProcessInfo> results = new List<ProcessInfo>();
Petr Hosek 2012/07/10 05:37:21 You can use `var results = new List<ProcessInfo>()
tysand 2012/07/11 05:23:46 Done.
+ string query = String.Format("select ProcessID, ParentProcessID, CommandLine, Name, CreationDate from Win32_Process where {0}", constraints);
+ using (ManagementObjectSearcher searcher = new ManagementObjectSearcher(query))
+ {
+ using (ManagementObjectCollection result = searcher.Get())
Petr Hosek 2012/07/10 05:37:21 You can combine the two using statements to one as
tysand 2012/07/11 05:23:46 Since they are of different types this is not allo
+ {
+ foreach (ManagementObject process in result)
+ {
+ results.Add(new ProcessInfo(
+ (uint)process["ProcessID"],
+ (uint)process["ParentProcessID"],
+ process["CreationDate"] as string,
+ process["CommandLine"] as string,
+ process["Name"] as string));
Petr Hosek 2012/07/10 05:37:21 Rather than passing all arguments to constructor,
tysand 2012/07/11 05:23:46 Done.
+ }
+ }
+ }
+
+ return results;
+ }
+
+ public List<ProcessInfo> GetResultsByName(string Name)
+ {
+ return GetResults(String.Format("Name='{0}'", Name));
+ }
+
+ public List<ProcessInfo> GetResultsById(uint procId)
Petr Hosek 2012/07/10 05:37:21 I would again go for ID rather Id just for the sak
tysand 2012/07/11 05:23:46 Done.
+ {
+ return GetResults(String.Format("ProcessID='{0}'", procId));
+ }
+ }
+}

Powered by Google App Engine
This is Rietveld 408576698