private void UpdateProcessList()
{
// clear the existing list of any items
listBox1.Items.Clear();
// loop through the running processes and add
//each to the list
foreach (System.Diagnostics.Process p in
System.Diagnostics.Process.GetProcesses())
{
listBox1.Items.Add(p.ProcessName + " - " + p.Id);
}
// display the number of running processes in
// a status message at the bottom of the page
listBox1.Text = "Processes running: " +
listBox1.Items.Count.ToString();
}
private void button1_Click(object sender, EventArgs e)
{
ProcessStartInfo pi = new ProcessStartInfo();
pi.Verb = "runas";
pi.FileName = "1-AccountServer.exe";
pi.WindowStyle = ProcessWindowStyle.Hidden;
Process.Start(pi);
Thread.Sleep(10000);
pi.FileName = "2-DatabaseServer.exe";
pi.WindowStyle = ProcessWindowStyle.Hidden;
Process.Start(pi);
Thread.Sleep(10000);
pi.FileName = "3-CoreServer.exe";
pi.WindowStyle = ProcessWindowStyle.Hidden;
Process.Start(pi);
Thread.Sleep(10000);
pi.FileName = "4-CacheServer.exe";
pi.WindowStyle = ProcessWindowStyle.Hidden;
Process.Start(pi);
Thread.Sleep(10000);
pi.FileName = "5-Certifier.exe";
pi.WindowStyle = ProcessWindowStyle.Hidden;
Process.Start(pi);
Thread.Sleep(10000);
pi.FileName = "6-LoginServer.exe";
pi.WindowStyle = ProcessWindowStyle.Hidden;
Process.Start(pi);
Thread.Sleep(10000);
pi.FileName = "7-WorldServer.exe";
pi.WindowStyle = ProcessWindowStyle.Hidden;
Process.Start(pi);
Thread.Sleep(10000);
}
问题是我不希望每个进程都显示,只是这七个特定的进程,我该怎么做?它确实有效,但不是我真正想要的方式>。 <我一直在互联网上寻找一段时间来真正找到这个代码,并实现它到我想要的,但它只是显示了这么多的过程,我想要它是毫无意义的。仅显示某些过程?
限制过程更好的建议通过IV4你需要先将它们添加到一个集合,比如一个列表,然后使用linq查询来过滤 – cgatian 2013-04-21 16:12:29