I'm trying to kill a process on a remote machine. But I get error. What am I doing wrong and how can I make this work?
My code:
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();
}
Just to clarify ImpersonateUser, it makes me login to the remote machine with correct user rights. So the problem is not there. When I debug and check the process object I find the correct process ID for notepad in this case. So the connection works fine. But when I try to kill the process I get this error:
System.NotSupportedException: Feature is not supported for remote machines. at System.Diagnostics.Process.EnsureState
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…