LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to determine if external exe is running before calling "System Exec.vi"

Solved!
Go to solution
I initiate another executable function from within my LabView code. I'd like to check if the other function is running before I make the call.
 
Only one copy of the other executable can run at one time, and my operator may have already started it before using the LabView code.
 
Thanks
 
0 Kudos
Message 1 of 11
(10,848 Views)
You could call an API function to list all the processes running, and search the list for your process.  See this link.
If you could rewrite the exe, you could set a registry key, or even write something to a file, when the exe is first executed. Then your LV code can check the registry key or check the file before it launches system exec.
- tbob

Inventor of the WORM Global
0 Kudos
Message 2 of 11
(10,839 Views)
Solution
Accepted by topic author Rick N.
A slightly easier way is to use use system exec to execute the tasklist command. Parsing this commands output will be easier than writing a bunch of code to use the Windows APIs. Running tasklist /NH /FI "IMAGENAME eq tasklist.exe" produces the output below.
 
tasklist.exe                  1796 Console                    1      5,916 K
If the exe is not running, it will output this.
 
INFO: No tasks are running which match the specified criteria.
Now all you have to do is some string parsing.
Message 3 of 11
(10,833 Views)
tasklist worked well

thanks
0 Kudos
Message 4 of 11
(10,827 Views)

I'm going to have to commit this one to memory or myself

"Now where did I put my memory, Oh YA it's inside my brain, DUH"




Joe.
"NOTHING IS EVER EASY"
0 Kudos
Message 5 of 11
(10,821 Views)
This should be a nugget, unless Darren has already put this one out.
- tbob

Inventor of the WORM Global
0 Kudos
Message 6 of 11
(10,815 Views)

Hi,

 

I tried the suggestion given by you. But I am getting different output every time.

 

How can I determine whether my exe is running or not?

 

Regards,

Rathnam.M

Regards,
Rathnam.M(CLAD),
Nokia Siemens Network
0 Kudos
Message 7 of 11
(10,038 Views)

You are getting a different output because the task list is changing every time you run it.  However, if the exe you are interested in is running, it will be listed in the output from tasklist, no matter what else is there.  Just search the list for the exe you want.  If the search results turn up empty, the exe is not running.  You must know the exact name of the exe.  To see what it is called, run tasklist in a cmd window.  Notice the list of tasks running.  Then run your exe and run tasklist again.  Look for the exe name.  This is what you should search for.

- tbob

Inventor of the WORM Global
0 Kudos
Message 8 of 11
(10,008 Views)

Here is some code that will determine if an exe is running.  I used Search and Replace String because I can set the ignore case to true so I don't have to exactly match the case.  Some tasks show up as all upper case, such as WINWORD.EXE.  By setting ignore case to True, I can type winword.exe in my search control.

 

IsExeRunning_BD.png

- tbob

Inventor of the WORM Global
Message 9 of 11
(10,001 Views)

Thank you. Sorry for the late reply.

Regards,
Rathnam.M(CLAD),
Nokia Siemens Network
0 Kudos
Message 10 of 11
(9,945 Views)