检查流程是否存在 [英] Check for process existing

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

问题描述

你好,

我编写代码并使用MFC.
我想检查进程是否存在.

例如:

Hello,

I write a code and using MFC.
I want to check if process exists or not.

for example:

if (myProcess.exe exists)
  do something
else
  do something else



我该怎么办?

谢谢



How can I do it?

Thanks

推荐答案

如果您要查找的进程具有GUI,则可以使用FindWindow来查看该窗口是否存在.如果是这样,则表明该进程正在运行.如果不是,则不一定意味着不是-它可能在其他Window站中运行.

如果您可以修改要检测的过程的源代码,则可以创建一个命名信号量,并在每次启动过程时将其引发.然后,检测过程可以按名称查找信号量.

如果您无法控制源代码,则可以使用Toolhelp API来疏通使用CreateToolHelp32SnapshotProcess32FirstProcess32First运行的所有进程. [
If the process you''re looking for has a GUI then you can use FindWindow to see if the window exists. If it does, the process is running. If not it doesn''t necessarily mean it''s not - it could be running in a different window station.

If you can modify the source code for the process you want to detect you could create a named semaphore and raise it everytime the process is launched. Then the detecting process can look for the semaphore by name.

If you don''t have control over the source code you can use the toolhelp API to dredge through all the processes running using CreateToolHelp32Snapshot, Process32First and Process32First. This[^] article has a code example, bit crap but still usable.


我在这里的文章中进行了过程枚举和搜索过程:

专业系统库:简介 [
I did process enumeration and searching for a process in my article here:

Professional System Library: Introduction[^]

You will see that the demo itself lists processes, and allows you to kill one.


看看是否有帮助:

http://msdn.microsoft.com/en-us/library/ms682623(VS .85).aspx [ ^ ]
See if this helps:

http://msdn.microsoft.com/en-us/library/ms682623(VS.85).aspx[^]


这篇关于检查流程是否存在的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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