[转]Terminate / kill /close process on remote machine using WMI
The following code can be used to close instance of visual studio on remote machine provided you have access to it. It kills the instance of it. This way you can make your colleague frustrated.
// connection will required user having access to remote m/c
System.Management.ConnectionOptions
conO = new System.Management.ConnectionOptions();
conO.Username = "DOMAIN\\sandeep";
conO.Password = "*******";
System.Management.ManagementScope
oMs = new System.Management.ManagementScope(@"\\<remoteMachineName>\root\cimv2",conO);
//get all the Processes running on remote m/c
System.Management.ObjectQuery oQuery = new System.Management.ObjectQuery("Select
* from Win32_Process");
//Execute the query
System.Management.ManagementObjectSearcher oSearcher = new System.Management.ManagementObjectSearcher(oMs,oQuery);
//Get the results
System.Management.ManagementObjectCollection oReturnCollection = oSearcher.Get();
//loop through found process and terminate
foreach (System.Management.ManagementObject oReturn in oReturnCollection)
{
string[] argList = new string[] { string.Empty };
//Name of process
if (oReturn["Name"].ToString().ToLower() == "devenv.exe")
{
object[] obj = new object[] { 0 };
oReturn.InvokeMethod("Terminate", obj);
}
}
Ref:
sandeep: http://inquest.wordpress.com/2008/04/08/terminate-process-on-remote-machine-using-wmi/
出处:http://www.cnblogs.com/
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。