检查一些exe程序是否在Windows上运行 [英] check if some exe program is running on the windows
问题描述
如何在Windows上检查某个.exe程序是否正在运行(正在进行中)?
How to check if some .exe program is running (is in process) on Windows?
我正在制作更新一个.exe程序的java应用程序。因此,如果某个客户端使用该exe程序,我的应用程序会要求关闭exe程序,并在关闭后自动替换新的.exe文件。
I'm making java application which update one .exe program. So, if that exe program is used by some client, my application ask for closing exe program, and after closing automatically replace .exe file with new one.
推荐答案
您可以在java程序中运行以下语句。在此之前,您需要知道任务管理器
中任务的名称。假设你想看MS-Word正在运行。然后运行MS-Word,转到任务管理器,在进程选项卡下,您应该看到名为 word.exe
的进程。找出您要定位的流程的名称。完成后,您只需运行以下代码:
You can run the following statement in your java program. Before that you need to know the name of the task in task manager
. Say you want to see MS-Word is running. Then run MS-Word, go to task manager and under the process tab, you should see a process named word.exe
. Figure out the name for the process you are targeting. Once you have that, you just run the following code:
String line;
String pidInfo ="";
Process p =Runtime.getRuntime().exec(System.getenv("windir") +"\\system32\\"+"tasklist.exe");
BufferedReader input = new BufferedReader(new InputStreamReader(p.getInputStream()));
while ((line = input.readLine()) != null) {
pidInfo+=line;
}
input.close();
if(pidInfo.contains("your process name"))
{
// do what you want
}
这篇关于检查一些exe程序是否在Windows上运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!