Thursday, May 13, 2010

WMI C# and Process Killing App


This little application demonstrates how to use custom WMI commands and how to kill processes and applications using Process Class in C#:


public static IList SimpleWMI(string query,
string machine)
{
ManagementScope scope = new ManagementScope("\\\\" +
machine + "\\root\\cimv2");
scope.Connect();
ObjectQuery queryExec = new ObjectQuery(query);
ManagementObjectSearcher searcher =
new ManagementObjectSearcher(scope, queryExec);
using (searcher)
using (ManagementObjectCollection collection = searcher.Get())
{
ManagementBaseObject[] array =
new ManagementBaseObject[collection.Count];
collection.CopyTo(array, 0);
return array;
}
}

No comments:

Post a Comment