12-15-2009 08:44 PM
12-16-2009 10:28 AM
Not sure if all this is can really be helpful (I didn't tested it), but usinf some SDK functions you could:
12-16-2009 11:15 AM
There is the CheckForDuplicateAppInstance function but it is useful to you if you can edit the code of the executable you are calling.
Read the function help and see if it works for you.
12-17-2009 02:21 AM - edited 12-17-2009 02:21 AM
As far as I can understand CheckForDuplicateAppInstance cannot be of any help in this case. This function checks if there is another running instance of the program in execution, while tnggio wants to check another running app. Additionally, the function does not give any handle to the running application, so there is no possibility to terminate it in any way.
But let's see if tanggio comments this: it may be that the situation is not as I have figured it.
12-17-2009 04:44 AM
Yeah, I'm aware that function maybe helpful only for specific conditions where the exe code (hopefully written in CVI) being run needs to be available.
But if this is the case that exe can call CheckForDuplicateAppInstance and close itself if already being run.
That was best shot since I could not help much with the SDK 😉
12-17-2009 09:08 AM
I had to write something similar recently, so I thought I'd post a simplified version of my code (most error handling removed for clarity's sake). It is almost exactly what Roberto described, and does not try to account for any special cases. When running this code under CVI, you will have to add psapi.lib to the project.
Should hopefully help get you started.
NickB
National Instruments
11-03-2010 03:23 PM
So I used the psapi.lib and example code from the earlier post-- all works fine in CVI6.0.
Now, we moved code to a CVI9 installation and it no longer worked--instead getting:
11-04-2010 09:18 AM - edited 11-04-2010 09:21 AM
Hello -
My best guess is that you're using a version of the psapi.h header file that did not ship with LabWindows/CVI 9.0 (perhaps using it from a windows sdk or visual studio installation). The reason for this guess is that in the most recent versions of the Win32 API (Windows 7, Server 2008 R2 and later), EnumProcesses, EnumProcessModules, etc, are defined as follows, and are exported from Kernel32.lib and Kernel32.dll:
In general, you should use the Win32 API headers and libs that ship with LabWindows/CVI to avoid this kind of thing.
NickB
National Instruments
04-11-2011 11:46 AM
Hi Nick-
I tried your sample program and received similar results. I added the psapi.h file from the CVI2010\sdk\include folder and at run time I get hte following errors:
04-11-2011 11:53 AM
Did you add psapi.lib from CVI2010\sdk\lib\msvc to your project? If not, just browse to that directory, and drag psapi.lib into your project tree.
As a general side note, when you are using CVI, you should only use the SDK include files and libs that install as part of the CVI installation - not the SDK you can download online. This is because CVI makes some changes to the header files to ensure compatibility with the CVI environment.
NickB
National Instruments