package org.killpid.actions;

import java.io.BufferedReader;
import java.io.InputStreamReader;

import org.eclipse.jface.action.IAction;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.IWorkbenchWindowActionDelegate;

/**
 * Our sample action implements workbench action delegate. The action proxy will
 * be created by the workbench and shown in the UI. When the user tries to use
 * the action, this delegate will be created and execution will be delegated to
 * it.
 * 
 * @see IWorkbenchWindowActionDelegate
 */
public class KillPidAction implements IWorkbenchWindowActionDelegate {
	private IWorkbenchWindow window;

	/**
	 * The constructor.
	 */
	public KillPidAction() {
	}

	/**
	 * The action has been activated. The argument of the method represents the
	 * 'real' action sitting in the workbench UI.
	 * 
	 * @see IWorkbenchWindowActionDelegate#run
	 */
	public void run(IAction action) {
		try {
			String[] cmd = { "tasklist" };
			Process proc = Runtime.getRuntime().exec(cmd);
			BufferedReader in = new BufferedReader(new InputStreamReader(proc.getInputStream()));
			String string_Temp = in.readLine();
			while (string_Temp != null) {
				System.out.println(string_Temp);
				if (string_Temp.indexOf("java.exe") != -1)
					Runtime.getRuntime().exec("taskkill /F /IM java.exe /T");
				if (string_Temp.indexOf("javaw.exe") != -1)
					Runtime.getRuntime().exec("taskkill /F /IM javaw.exe /T");
				string_Temp = in.readLine();
			}
		} catch (Exception e) {
		}
	}

	/**
	 * Selection in the workbench has been changed. We can change the state of
	 * the 'real' action here if we want, but this can only happen after the
	 * delegate has been created.
	 * 
	 * @see IWorkbenchWindowActionDelegate#selectionChanged
	 */
	public void selectionChanged(IAction action, ISelection selection) {
	}

	/**
	 * We can use this method to dispose of any system resources we previously
	 * allocated.
	 * 
	 * @see IWorkbenchWindowActionDelegate#dispose
	 */
	public void dispose() {
	}

	/**
	 * We will cache window object in order to be able to provide parent shell
	 * for the message dialog.
	 * 
	 * @see IWorkbenchWindowActionDelegate#init
	 */
	public void init(IWorkbenchWindow window) {
		this.window = window;
	}
}
最近下载更多
102128742  LV1 2021年4月9日
luohaipeng  LV23 2019年11月20日
低调人  LV38 2019年8月4日
songgo  LV13 2018年9月29日
幽幻梦之韩霜  LV10 2018年9月4日
sadfasdfasdf  LV1 2018年1月23日
g13721549833  LV13 2017年12月2日
chongzi  LV15 2017年7月12日
kisn888  LV14 2016年7月25日
情深不寿天  LV2 2016年3月12日
最近浏览更多
感冒灵颗粒 2023年3月17日
暂无贡献等级
微信网友_5992582549164032  LV6 2023年2月16日
2011502295  LV6 2022年12月27日
12cq345  LV6 2022年5月25日
何为人 2021年6月9日
暂无贡献等级
102128742  LV1 2021年4月9日
w19991213  LV2 2020年9月21日
CurryKevin  LV8 2020年6月22日
Justice_fd 2020年4月23日
暂无贡献等级
amour  LV7 2020年3月15日
顶部 客服 微信二维码 底部
>扫描二维码关注最代码为好友扫描二维码关注最代码为好友