LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

How to know if an application is already running

Hi,
I have an application that has to run forever on a machine, but
sometimes crashes (I'm working on it!).
So I want to add it to scheduled tasks, in order that it starts,
checks if a copy of the program is already running, and in case it is,
exits. How can I know if a copy of an exe is running or not?
Thanks.
0 Kudos
Message 1 of 6
(4,397 Views)
You can use CheckForDuplicateAppInstance () to perform this check. Look at the on-line help for this function for a description, and at oneinst.prj in samples >> utility directory for an example of use.

Hope this helps
Roberto


Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
0 Kudos
Message 2 of 6
(4,397 Views)
Here is a bit of sample code with CheckForDuplicateAppInstance():

#include
int main (int argc, char *argv[])
{
int thereIsAnother;
if (InitCVIRTE (0, argv, 0) == 0)
return -1; /* out of memory */
if (CheckForDuplicateAppInstance (ACTIVATE_OTHER_INSTANCE, &thereIsAnother) < 0)
return -1;
/* out of memory, or not Win 2000/NT/9x */
if (thereIsAnother)
return 0; /* prevent duplicate instance */
return 0;
}

Good Luck,
Ted F.
National Instruments
0 Kudos
Message 3 of 6
(4,397 Views)

Hi,

How can I do this in Labview? Thanks.

0 Kudos
Message 4 of 6
(4,029 Views)

A couple of comments:

1. You should post this on the LabVIEW board for more responses. This is for CVI, a C Development Environment.
2. You could use the Call Library Function Node to call the Windows SDK (EnumProcesses and Process32Next) and check to see if the process is running.
3. Better yet, if the crash that occurs does not kill LabVIEW, a better solution might be to create a top level VI that simply calls your VI in a loop. If your VI errors out, it simply returns to the top-level VI and re-starts in the next loop iteration.

Jervin Justin
NI TestStand Product Manager
0 Kudos
Message 5 of 6
(3,989 Views)

CheckForDuplicateAppInstance only checks for a duplicate of the same executable, what if you have 2 Versions of the same Executable and try to run both?  It appears that this does not catch multiple instances unless it is the exact same executable running.

0 Kudos
Message 6 of 6
(3,256 Views)