确定进程是否正在运行. [英] To Determine whether the Process is running or not.

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

问题描述

大家好..

以编程方式试图在Microsoft Office 2007上运行.代码如下所示:

Hello Everyone..

Programatically am trying to run on Microsoft office 2007. The code looks like this:

char exe_arr[100]="E:\\setup.exe";
HINSTANCE hInst = ShellExecute(0,"open",exe_arr,"",0,SW_SHOW);



无论如何,执行此命令后,代码将打开office setup.exe ...

后者确定exe的状态,即,如果exe正在运行,则状态为1,如果exe退出,则状态为0.

要确定exe状态,代码如下所示:



Anyhow after executing this, The code opens the office setup.exe...

And latter Am determining the status of the exe i.e., If exe is running the status is 1, And if exe is quit the status is 0.

To determine the exe status, the code looks like this:

int isRunning;
isRunning=FIND_PROC_BY_NAME("setup.exe");



当我执行此代码时,即使setup.exe正在运行,FIND_PROC_BY_NAME也会返回0状态.它应该返回1状态吗?

但是此代码对于其他exe应用程序也能正常工作..

谁能说出为什么office setup.exe返回0状态?


在此先谢谢.. !!!!



When i execute this code, FIND_PROC_BY_NAME returns 0 status, eventhough setup.exe is running..& it should return 1 status right ?

But this code works fine for other exe applications..

Can anyone tell, Why it is returning 0 status for office setup.exe ??


Thanks in advance..!!

推荐答案

您可以使用 CreateProcess [
2.轮询是浪费处理器资源,而WFSO是一种更有效,更优雅的解决方案.

-PaulH
You can use GetExitCodeProcess[^] and check for STILL_ACTIVE (259) to see if the process is still running or not.

A better method than polling for process completion, I think, would be to create the process with CreateProcess[^], then use WaitForSingleObject on the process handle to know exactly when the process exits.

Two reasons this is a better method:

1. "setup.exe" may or may not refer to the "setup.exe" you started. There may be more than one instance.

2. polling is a waste of processor resources, WFSO is a more efficient and elegant solution.

-PaulH


您可以枚举所有活动进程列表,然后可以检查您的进程是否正在运行.如果该进程正在运行,则可以使用terminateprocess()窗口终止该进程功能;
您可以看一下以下示例
http://forums.codeguru.com/showthread.php?t=457604 [ ^ ]
you can enumerate all the active processes list and then you can check if your process is running or not.if the process is running,you can terminate that by using terminateprocess() window function;
you can have a look on the following sample
http://forums.codeguru.com/showthread.php?t=457604[^]


这篇关于确定进程是否正在运行.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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