获取使用 C# Process.Start 启动的程序的进程 ID
预先感谢您的所有帮助!
我目前正在 C# 2010 中开发一个程序,该程序启动 PLink (Putty) 来创建 SSH 隧道。我试图使程序能够跟踪每个打开的隧道,以便用户可以终止那些不再需要的实例。我目前正在使用 System.Diagnostics.Process.Start 来运行 PLink(当前正在使用 Putty)。我需要确定每个 plink 程序启动时的 PID,以便用户可以随意终止它。
问题是如何做到这一点,我是否使用了正确的 .Net 名称空间,或者是否有更好的东西?
代码片段:
private void btnSSHTest_Click(object sender, EventArgs e)
{
String puttyConString;
puttyConString = "-ssh -P " + cboSSHVersion.SelectedText + " -" + txtSSHPort.Text + " -pw " + txtSSHPassword.Text + " " + txtSSHUsername.Text + "@" + txtSSHHostname.Text;
Process.Start("C:\\Program Files (x86)\\Putty\\putty.exe", puttyConString);
}
Thanks in advance for all of your help!
I am currently developing a program in C# 2010 that launches PLink (Putty) to create a SSH Tunnel. I am trying to make the program able to keep track of each tunnel that is open so a user may terminate those instances that are no longer needed. I am currently using System.Diagnostics.Process.Start to run PLink (currently Putty being used). I need to determine the PID of each plink program when it is launched so a user can terminate it at will.
Question is how to do that and am I using the right .Net name space or is there something better?
Code snippet:
private void btnSSHTest_Click(object sender, EventArgs e)
{
String puttyConString;
puttyConString = "-ssh -P " + cboSSHVersion.SelectedText + " -" + txtSSHPort.Text + " -pw " + txtSSHPassword.Text + " " + txtSSHUsername.Text + "@" + txtSSHHostname.Text;
Process.Start("C:\\Program Files (x86)\\Putty\\putty.exe", puttyConString);
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我不确定我是否理解正确,但是
Process.Start
(至少是您正在使用的重载)将返回一个Process
,然后返回Process< /code> 有一个
Id
属性。I'm not sure if I understand correctly, but
Process.Start
(at least the overload you're using) will return aProcess
and then thatProcess
has anId
property.Process.Start 返回一个 Process 对象。使用
Process.Id
属性查找 ID。Process.Start returns a Process object. Use the
Process.Id
property to find out the id.你可以这样做:
You can do this: