|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Announcements
Chapters
Services
Feature Zones
|
IntroductionThis is the second article in the series of articles How To: (Almost) Everything In WMI via C#.
This article focuses on the ConsiderationPlease do not send me emails with instructions on how to perform these tasks using .NET native classes. That is not the point of these articles. I'm composing these articles for the purpose of demonstrating how to use WMI within C#.NET with the Using the Attached CodeMethods (Local Machine or Remote Machine)
Instantiate the Local Provider//using baileysoft.Wmi.Process; *must include
ProcessLocal processObject = new ProcessLocal();
Walkthrough All the Methods //Get Running Processes
Console.WriteLine("Fetching Running Processes: ");
foreach (string eachProcess in processObject.RunningProcesses())
{
Console.WriteLine("Process: " + eachProcess);
}
Console.WriteLine("");
//Start Process
string processName = "notepad.exe";
Console.WriteLine("Creating Process: " + processName);
Console.WriteLine(processObject.CreateProcess(processName));
//Change the Priority
Console.WriteLine("Setting Process Priority: Idle");
processObject.SetPriority(processName, ProcessPriority.priority.IDLE);
//Get the Owner of a Process
Console.WriteLine("Process Owner: " + processObject.GetProcessOwner(processName));
//Get the Process Owner's SID
Console.WriteLine("Process Owner SID: " +
processObject.GetProcessOwnerSID(processName));
Console.WriteLine("");
//Get a collection of all the Properties of a Process (Memory Usage, etc, etc)
Console.WriteLine("Properties of Process: " + processName);
foreach (string property in processObject.ProcessProperties(processName))
{
Console.WriteLine(property);
}
Console.WriteLine("");
//Terminate a Process
Console.WriteLine("Killing Process: " + processName);
processObject.TerminateProcess(processName);
Console.WriteLine("Process Terminated");
Console.ReadLine();
Remote System ProcessesIn order to run the code above against a remote machine, you must instantiate the Instantiating the Remote Provider//using baileysoft.Wmi.Process; *must include
ProcessRemote processObject =
new ProcessRemote(userName,
password,
domain,
machine/ip);
Connecting to a Remote Machine Where You Want to Use The Domain Credentials from the LoggedIn UserProcessRemote processObject =
new ProcessRemote(null,
null,
null,
machine/ip);
Using a Service Account to kick off a Remote ProcessProcessRemote processObject =
new ProcessRemote("neal.bailey",
"S3cr3tPa$$",
"BAILEYSOFT",
"192.168.2.1");
processObject.OneOfTheMethodsDetailedAbove;
ConclusionThe WMI (Windows Management Instrumentation) provider is considerably slower than the native .NET classes. At first it may seem pointless to use WMI for process management tasks considering the ease of use of the .NET History
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||