using System.Management; // Get the process object for "notepad.exe" ManagementObject process = new ManagementObject("win32_process.Name='notepad.exe'"); // Invoke the "Terminate" method of the process object object[] methodArgs = { }; process.InvokeMethod("Terminate", methodArgs);
using System.Management; // Get the volume object for "C:\" drive ManagementObject volume = new ManagementObject("win32_volume.Name='C:\\\\'"); // Invoke the "DefragAnalysis" method of the volume object and get the result object[] methodArgs = { }; object result = volume.InvokeMethod("DefragAnalysis", methodArgs);This example uses the ManagementObject class to get a reference to the "C:\" drive and then invokes the "DefragAnalysis" method on the volume object to analyze the defragmentation status of the drive. These examples both use the System.Management package library, which is included in the .NET Framework.