我有两个调用ScreenScaper.exe
的C#应用程序;当一个退出时,我不希望它结束任何名为Screenscaper.exe
的内容,我希望它结束特定的进程ID。
如何通过进程ID以编程方式结束应用程序;这也意味着当我以编程方式生成应用程序时如何获取ProcessID?
答案 0 :(得分:0)
CreateToolhelp32Snapshot可以帮助您找到父(==关联?)进程ID。
例如,让我们假设您要杀死所有" ScreenScraper.exe"没有父进程的进程(即在正常关闭过程中被挂起的进程)。然后代码可能如下所示:
myProcessEx
// create a couple arrays of y-values to plot:
Number[] domainLabels = {1, 2, 3, 6, 7, 8, 9, 10, 13, 14};
Number[] series1Numbers = {1, 4, 2, 8, 4, 16, 8, 32, 16, 64};
Number[] series2Numbers = {5, 2, 10, 5, 20, 10, 40, 20, 80, 40};
// turn the above arrays into XYSeries':
// (Y_VALS_ONLY means use the element index as the x value)
//XYSeries series1 = new SimpleXYSeries(Arrays.asList(series1Numbers), SimpleXYSeries.ArrayFormat.Y_VALS_ONLY, "Series1");
XYSeries series1 = new SimpleXYSeries(Arrays.asList(domainLabels), Arrays.asList(series1Numbers), "Series1");
//XYSeries series2 = new SimpleXYSeries(Arrays.asList(series2Numbers), SimpleXYSeries.ArrayFormat.Y_VALS_ONLY, "Series2");
XYSeries series2 = new SimpleXYSeries(Arrays.asList(domainLabels), Arrays.asList(series2Numbers), "Series2");
//...other lines
plot.setDomainValueFormat(new Format() {
@Override
public StringBuffer format(Object obj, StringBuffer toAppendTo, FieldPosition pos) {
int day = ((Number) obj).intValue();
System.out.println(day);
return new StringBuffer(day);
}
@Override
public Object parseObject(String source, ParsePosition pos) {
return null;
}
});
// reduce the number of range labels
//plot.setTicksPerRangeLabel(3);
// rotate domain labels 45 degrees to make them more compact horizontally:
plot.getGraphWidget().setDomainLabelOrientation(-45);
课程来自http://www.pinvoke.net/default.aspx/kernel32.createtoolhelp32snapshot的示例代码部分。
请注意,可以重用已终止的父进程ID(https://stackoverflow.com/a/185298/4295017),因此您可能需要更详细地详细说明父检查代码。