【发布时间】:2014-11-01 20:29:15
【问题描述】:
我正在尝试终止远程计算机上的进程。但我得到错误。我做错了什么,我该如何做?
我的代码:
var iu = new ImpersonateUser();
try
{
iu.Impersonate(Domain, _userName, _pass);
foreach (var process in Process.GetProcessesByName("notepad", "RemoteMachine"))
{
string processPath = pathToExe; //Is set as constant (and is correct)
process.Kill();
Thread.Sleep(3000);
Process.Start(processPath);
}
}
catch (Exception ex)
{
lblStatus.Text = ex.ToString();
}
finally
{
iu.Undo();
}
只是为了澄清 ImpersonateUser,它让我以正确的用户权限登录到远程机器。所以问题不存在。当我调试和检查进程对象时,在这种情况下,我找到了记事本的正确进程 ID。所以连接工作正常。但是当我尝试终止进程时,我得到了这个错误:
System.NotSupportedException: Feature is not supported for remote machines. at System.Diagnostics.Process.EnsureState
【问题讨论】:
-
来自我之前删除的未回答:来自 Micrsoft 在
Process.Kill上的文档:You are attempting to call Kill for a process that is running on a remote computer. The method is available only for processes running on the local computer.
标签: c# process remote-access kill-process