Opening an already open program on PC

I was wondering if it is possible to open a program on your PC that is already running.

I'm aware that I can open programs out of my file folder with the function system.util.execute but after you have used that function to open a program in your client and click on the client, the program falls back. If you press the button with the system.util.execute again it will open a new one.
The problem that I want to avoid is that some operator is going to open a lot of the same programs. Thank you in advance

Little example:

Here it opens a VNC viewer but when I'm going to work in the client it disappears. What most operators will do is click the button of Open VNC again and then you will have 2 programs running the same VNC view. this will happen again and again until there are a lot of programs running in the background

You forgot to mention which operating system you're using.

If it's Windows, I think you might want to launch a batch file instead and have that check (somehow) if the program is already running. I'm not sure how.

Check Stack Overflow.

The top scoring answer (> 380 votes) uses

tasklist /fi "ImageName eq MyApp.exe" /fo csv 2>NUL | find /I "myapp.exe">NUL
if "%ERRORLEVEL%"=="0" echo Program is running

I think you would replace the echo command with exit (check this) and put myapp.exe on the third line to start the program.

Yes, it is Windows that I’m using. I will try your suggestion and let you know

It doesn't work sadly. It is giving the following error:

Parse error for event handler "actionPerformed" SyntaxError: ('no viable alternative at input \'"ImageName eq kladblok.exe"\'', ('<string>', 1, 13, 'tasklist /fi "ImageName eq kladblok.exe" /fo csv 2>NUL | find /I "myapp.exe">NUL\n'))

Show your code!

tasklist /fi "ImageName eq kladblok.exe" /fo csv 2>NUL | find /I "kladblok.exe">NUL
if "%ERRORLEVEL%"=="0" exit Program is running
system.util.execute(['C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Accessories\kladblok.exe'])

Shouldn't the first two lines be in a batch (.bat) file saved on the gateway. Then your script calls the batch file. Those two lines are Windows Command Line, not Python.

It should be something like this:


tasklist /fi "ImageName eq kladblok.exe" /fo csv 2>NUL | find /I "kladblok.exe">NUL
if "%ERRORLEVEL%"=="0" exit 
rem It doesn't seem to be running already. Start it now.


system.util.execute(['C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Accessories\kladblok.bat'])

You might need an additional line on the script to set the focus onto kladblok.exe. I don't know about that.

ah I was already a bit confused but I don't know about saving files on the gateway, so where can I do that in the gateway?

I don't know. You'll have to figure out where Ignition is going to look for scripts. See if you can run a Python function to report the default directory for system.util.execute..

Oh okay I will try!! Thanks for the help.