我为一家地方议会工作,不知为何,他们购买了一款在使用 Java 时非常不稳定的应用程序。某些网页屏幕无法启动,我发现解决该问题的唯一方法是打开 Java 控制台,然后立即关闭它而不执行任何其他操作。不幸的是,我被告知,当数百人将使用该系统时,这不是一个令人满意的解决方案。我编写了一个批处理文件,它将在打开 IE URL 之前打开和关闭控制台(见下文)。
Start /wait "" "C:\Program Files\Java\jre6\bin\javacpl.exe"
ECHO Opening JAVA Console
timeout 4
TASKKILL /F /IM javacpl.exe
那么问题就在于,它会终止 PC 上运行的所有 Java 会话,而不仅仅是控制台。因此,人们无法运行该应用程序的多个版本,即测试版、开发版、训练版和/或实时版。有没有办法只关闭控制台,而让所有其他 Java 实例继续运行?
谢谢
答案1
如果您查看 taskkill 命令,您会看到 taskkill 开关:
TASKKILL [/S system [/U username [/P [password]]]]
{ [/FI filter] [/PID processid | /IM imagename] } [/T] [/F]
Description:
This tool is used to terminate tasks by process id (PID) or image name.
Parameter List:
/S system Specifies the remote system to connect to.
/U [domain\]user Specifies the user context under which the
command should execute.
/P [password] Specifies the password for the given user
context. Prompts for input if omitted.
/FI filter Applies a filter to select a set of tasks.
Allows "*" to be used. ex. imagename eq acme*
/PID processid Specifies the PID of the process to be terminated.
Use TaskList to get the PID.
/IM imagename Specifies the image name of the process
to be terminated. Wildcard '*' can be used
to specify all tasks or image names.
/T Terminates the specified process and any
child processes which were started by it.
/F Specifies to forcefully terminate the process(es).
/? Displays this help message.
Filters:
Filter Name Valid Operators Valid Value(s)
----------- --------------- -------------------------
STATUS eq, ne RUNNING |
NOT RESPONDING | UNKNOWN
IMAGENAME eq, ne Image name
PID eq, ne, gt, lt, ge, le PID value
SESSION eq, ne, gt, lt, ge, le Session number.
CPUTIME eq, ne, gt, lt, ge, le CPU time in the format
of hh:mm:ss.
hh - hours,
mm - minutes, ss - seconds
MEMUSAGE eq, ne, gt, lt, ge, le Memory usage in KB
USERNAME eq, ne User name in [domain\]user
format
MODULES eq, ne DLL name
SERVICES eq, ne Service name
WINDOWTITLE eq, ne Window title
NOTE
----
1) Wildcard '*' for /IM switch is accepted only when a filter is applied.
2) Termination of remote processes will always be done forcefully (/F).
3) "WINDOWTITLE" and "STATUS" filters are not considered when a remote
machine is specified.
Examples:
TASKKILL /IM notepad.exe
TASKKILL /PID 1230 /PID 1241 /PID 1253 /T
TASKKILL /F /IM cmd.exe /T
TASKKILL /F /FI "PID ge 1000" /FI "WINDOWTITLE ne untitle*"
TASKKILL /F /FI "USERNAME eq NT AUTHORITY\SYSTEM" /IM notepad.exe
TASKKILL /S system /U domain\username /FI "USERNAME ne NT*" /IM *
TASKKILL /S system /U username /P password /FI "IMAGENAME eq note*"
您也许能够使用TASKKILL /FI "Windows title"
它来终止遇到问题的特定实例。
您也可以在 PowerShell 中执行基本相同的操作,但还有其他潜在途径可以尝试并做出更好的猜测。
例如,您可以查看各种 Java.exe 的运行时间并仅终止正确的那个:
Get-Process -Name "java" | where {$_.Starttime -lt 100}