检查某些 exe 程序是否在 Windows 上运行 [英] check if some exe program is running on the windows

查看:32
本文介绍了检查某些 exe 程序是否在 Windows 上运行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何检查某些 .exe 程序是否在 Windows 上运行(正在处理)?

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆