我正在尝试在远程计算机上执行 notepad.exe,但现在无法正常工作。我错过了什么?
var ui = new ImpersonateUser();
//the process to restart
const string processName = "notepad.exe";
var serverName = "serverName";
try
{
//Use adbadmin for access
ui.Impersonate(_domain, _userName, _pass);
//Start the process
ProcessStartInfo info = new ProcessStartInfo("C:\\PsTools");
info.FileName = @"C:\PsTools\psexec.exe";
info.Arguments = @"""\\" + serverName + @"C:\WINDOWS\notepad.exe""";
info.RedirectStandardOutput = true;
info.UseShellExecute = false;
Process p = Process.Start(info);
lblStatusResponse.Text = "Service " + processName + " was restarted correctly.";
}
catch (Exception ex)
{
lblStatusResponse.Text = ex.ToString();
}
finally
{
ui.Undo();
}
这也不给我异常(exception),但我肯定错过了一些东西......
最佳答案
答案是您的回复的组合。但整个正确的解决方案是:
ProcessStartInfo info = new ProcessStartInfo("C:\\PsTools");
info.FileName = @"C:\PsTools\psexec.exe";
info.Arguments = @"\\" + serverName + @" -i C:\WINDOWS\notepad.exe";
info.RedirectStandardOutput = true;
info.UseShellExecute = false;
Process p = Process.Start(info);
关于c# - 在远程机器上执行exe,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/25782308/