Feroz Khan

Feroz Khan

  • 1.1k
  • 300
  • 92.3k

how can i kill any app through c# from remote machine

Jul 27 2015 4:25 AM
i am using below code but showing error like - Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED)) 
         
var option = new ConnectionOptions();
option.Username = sys_admin_user_txt.Text;
option.Password = sys_admin_password_txt.Text;
var Kill = exe_name_txt.Text;
//string Kill = exe_name_txt.Text;
ManagementScope scope = new ManagementScope(@"\\"+ ftp +"\\root\\cimv2", option);
// WMI query
var query = new SelectQuery("select * from Win32_process where name = '" + Kill + "'");
using (var searcher = new ManagementObjectSearcher(scope, query))
{
foreach (ManagementObject process in searcher.Get()) // this is the fixed line
{
process.InvokeMethod("Terminate", null);
}

Answers (4)