現在実行中のプロセスのリストボックスを持つタスクキラープログラムがあります。アイテムを選択すると、ボタンをクリックするとコードが実行され、選択したタスクが終了します。すべて正常に動作しますが、私が助けが必要なのは、最後のタスクが何を殺したかを表示するフォーム上の文字列出力を操作することです。たとえば、電卓を開いてそのタスクを終了すると、私の文字列出力は "System.Diagnostics.Process(calc)"です。これがちょうど「calc」と言うのなら、私は好きです。だから私はcで出力文字列を操作する
public bool KillProcess(ListBox PList, TextBox Killed)
{
bool Kill = true;
string x = "";
Killed.Text = "";
if (PList.SelectedItem != null)
{
foreach (Process p in Process.GetProcesses(Environment.MachineName))
{
x = PList.SelectedItem.ToString();
if (p.ProcessName.Equals(x))
{
try
{
p.Kill();
//*************** Here is where I have the process killed placed into a textbox
//Which I would like to not say "System.Diagnostics.Process..."
Killed.Text = p.ToString();
}
catch
{
MessageBox.Show(p.ProcessName.ToString() + " cannot be killed. ", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
Kill = false;
}
}
}
}
else
{
MessageBox.Show("Please select a process to be killed.", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
Kill = false;
}
return Kill;
}
なぜ単純にp.ProcessNameを使用しないのですか? – BlackBear