# Opening an already open program on PC

**URL:** <https://forum.inductiveautomation.com/t/opening-an-already-open-program-on-pc/82825>\
**Category:** Ignition\
**Tags:** vision\
**Created:** [December 7, 2023, 7:41am UTC](https://forum.inductiveautomation.com/t/opening-an-already-open-program-on-pc/82825 "2023-12-07T07:41:37Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![Stef\_Velers](https://avatars.discourse-cdn.com/v4/letter/s/bc8723/32.png) [@Stef\_Velers](https://forum.inductiveautomation.com/u/Stef_Velers)\
**Post date:** [December 7, 2023, 7:41am UTC](https://forum.inductiveautomation.com/t/opening-an-already-open-program-on-pc/82825/1 "2023-12-07T07:41:37Z")

</div>

Hi,  
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

---

<div class="post-metadata">

**Author:** ![Stef\_Velers](https://avatars.discourse-cdn.com/v4/letter/s/bc8723/32.png) [@Stef\_Velers](https://forum.inductiveautomation.com/u/Stef_Velers)\
**Post date:** [December 7, 2023, 7:45am UTC](https://forum.inductiveautomation.com/t/opening-an-already-open-program-on-pc/82825/2 "2023-12-07T07:45:40Z")

</div>

Little example:

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/8/b/8b17793a9d3ecff839e6feaee007465a7659f675.png)  
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

---

<div class="post-metadata">

**Author:** ![Transistor](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/transistor/32/3380_2.png) [@Transistor](https://forum.inductiveautomation.com/u/Transistor)\
**Post date:** [December 7, 2023, 9:24am UTC](https://forum.inductiveautomation.com/t/opening-an-already-open-program-on-pc/82825/3 "2023-12-07T09:24:27Z")

</div>

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.

> <https://stackoverflow.com/questions/162291/how-to-check-if-a-process-is-running-via-a-batch-script>

The top scoring answer (\> 380 votes) uses

```auto
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.

---

<div class="post-metadata">

**Author:** ![Stef\_Velers](https://avatars.discourse-cdn.com/v4/letter/s/bc8723/32.png) [@Stef\_Velers](https://forum.inductiveautomation.com/u/Stef_Velers)\
**Post date:** [December 7, 2023, 10:03am UTC](https://forum.inductiveautomation.com/t/opening-an-already-open-program-on-pc/82825/4 "2023-12-07T10:03:45Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Stef\_Velers](https://avatars.discourse-cdn.com/v4/letter/s/bc8723/32.png) [@Stef\_Velers](https://forum.inductiveautomation.com/u/Stef_Velers)\
**Post date:** [December 8, 2023, 9:14am UTC](https://forum.inductiveautomation.com/t/opening-an-already-open-program-on-pc/82825/5 "2023-12-08T09:14:57Z")

</div>

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

```auto
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'))

```

---

<div class="post-metadata">

**Author:** ![Transistor](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/transistor/32/3380_2.png) [@Transistor](https://forum.inductiveautomation.com/u/Transistor)\
**Post date:** [December 8, 2023, 9:19am UTC](https://forum.inductiveautomation.com/t/opening-an-already-open-program-on-pc/82825/6 "2023-12-08T09:19:07Z")

</div>

Show your code!

---

<div class="post-metadata">

**Author:** ![Stef\_Velers](https://avatars.discourse-cdn.com/v4/letter/s/bc8723/32.png) [@Stef\_Velers](https://forum.inductiveautomation.com/u/Stef_Velers)\
**Post date:** [December 8, 2023, 9:23am UTC](https://forum.inductiveautomation.com/t/opening-an-already-open-program-on-pc/82825/7 "2023-12-08T09:23:41Z")

</div>

```auto
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'])

```

---

<div class="post-metadata">

**Author:** ![Transistor](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/transistor/32/3380_2.png) [@Transistor](https://forum.inductiveautomation.com/u/Transistor)\
**Post date:** [December 8, 2023, 9:34am UTC](https://forum.inductiveautomation.com/t/opening-an-already-open-program-on-pc/82825/8 "2023-12-08T09:34:32Z")

</div>

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:

**kladblok.bat**

```auto
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.
kladblok.exe

```

**Script**

```auto
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.

---

<div class="post-metadata">

**Author:** ![Stef\_Velers](https://avatars.discourse-cdn.com/v4/letter/s/bc8723/32.png) [@Stef\_Velers](https://forum.inductiveautomation.com/u/Stef_Velers)\
**Post date:** [December 8, 2023, 9:38am UTC](https://forum.inductiveautomation.com/t/opening-an-already-open-program-on-pc/82825/9 "2023-12-08T09:38:48Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![Transistor](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/transistor/32/3380_2.png) [@Transistor](https://forum.inductiveautomation.com/u/Transistor)\
**Post date:** [December 8, 2023, 9:42am UTC](https://forum.inductiveautomation.com/t/opening-an-already-open-program-on-pc/82825/10 "2023-12-08T09:42:29Z")

</div>

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`..

---

<div class="post-metadata">

**Author:** ![Stef\_Velers](https://avatars.discourse-cdn.com/v4/letter/s/bc8723/32.png) [@Stef\_Velers](https://forum.inductiveautomation.com/u/Stef_Velers)\
**Post date:** [December 8, 2023, 9:47am UTC](https://forum.inductiveautomation.com/t/opening-an-already-open-program-on-pc/82825/11 "2023-12-08T09:47:37Z")

</div>

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