현재 실행중인 프로세스의 목록 상자가있는 작업 킬러 프로그램이 있습니다. 항목을 선택하면 버튼 클릭으로 코드가 실행되어 선택한 작업이 종료됩니다. 그게 다 잘 작동하지만, 내가 도움이 필요한 것은 마지막 작업이 무엇인지 표시하는 양식의 문자열 출력을 조작하는 것입니다. 예를 들어 계산기를 열어 해당 작업을 종료하면 문자열 출력은 "System.Diagnostics.Process (calc)"입니다. 이것이 "계산"이라고 말하면 더 좋을 것입니다. 그래서, 별도의 노트로, 또한 당신을C에서 출력 문자열 조작 #
Killed.Text = p.ProcessName;
을 시도
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