you can do it with both without problems. The only problem being is permission to kill a process on the remote computer. you need to have permission to do this and access rights
using WMI, be sure you added a reference to System.Management.dll and imported the namespaces, System.Management and System.Management.Instrumentation.
we then execute a query and execute the terminate command:
ManagementScope theScope = new ManagementScope("\\\\ComputerName\\root\\cimv2");
ObjectQuery theQuery = new ObjectQuery("SELECT * FROM Win32_Process WHERE Name='ApplicationName.exe'");
ManagementObjectSearcher theSearcher = new ManagementObjectSearcher(theScope, theQuery);
ManagementObjectCollection theCollection = theSearcher.Get();
foreach (ManagementObject theCurObject in theCollection)
Terminating a process using WMI
kangalert
Lawrence 007
Shabari
_Gerry_
Ibrahim Hamouda
pretty much how Sven posted, either doing it this way:
Process[] theList = Process.GetProcesses("machineName")
foreach(Process curProcess in theList)
{
if (curProcess.ProcessName.Equals("ProcessName"))
{
curProcess.Kill();
}
}
or this way:
Process[] theList = Process.GetProcessesByName("machineName", "ProcessName")
foreach(Process curProcess in theList)
{
curProcess.Kill();
}
brian_tsim
using WMI, be sure you added a reference to System.Management.dll and imported the namespaces, System.Management and System.Management.Instrumentation.
we then execute a query and execute the terminate command:
ManagementScope theScope = new ManagementScope("\\\\ComputerName\\root\\cimv2"); ObjectQuery theQuery = new ObjectQuery("SELECT * FROM Win32_Process WHERE Name='ApplicationName.exe'"); ManagementObjectSearcher theSearcher = new ManagementObjectSearcher(theScope, theQuery); ManagementObjectCollection theCollection = theSearcher.Get(); foreach (ManagementObject theCurObject in theCollection){
theCurObject.InvokeMethod(
"Terminate", null);}
AndyJ_PS
Thanks.
Nisa
Thanks
Cole Thompson
markgoldin
Ray Laubert
Norbert.Bender
It is:
Process.GetProcesses("remoteMachine") will give you a process collection of remoteMachine.
Process.GetProcessByName("notepad", "remoteMachine") will give you a collection of processes named notepad on remoteMachine.
Given that you have access rights on remoteMachine...
--
SvenC