# Gateway Event Script not triggering batch file

**URL:** <https://forum.inductiveautomation.com/t/gateway-event-script-not-triggering-batch-file/22643>\
**Category:** Ignition\
**Tags:** ignition79\
**Created:** [February 18, 2019, 1:43pm UTC](https://forum.inductiveautomation.com/t/gateway-event-script-not-triggering-batch-file/22643 "2019-02-18T13:43:02Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![bkarabinchak.psi](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/bkarabinchak.psi/32/83567_2.png) [@bkarabinchak.psi](https://forum.inductiveautomation.com/u/bkarabinchak.psi)\
**Post date:** [February 18, 2019, 1:43pm UTC](https://forum.inductiveautomation.com/t/gateway-event-script-not-triggering-batch-file/22643/1 "2019-02-18T13:43:02Z")

</div>

I am trying to trigger a batch file 5 pm everyday. It works while using a button that has the same exact script run when it is pressed, but not for a tag value change. I have set up logs and I know the script IS running except for the line that actually executes the batch.

The script in my on value change -

```auto
import system
myLogger = system.util.getLogger("DevLogger")
myLogger.info("In hour Change")
if system.tag.read("DayOfWeek").value==2 and system.tag.read("HourOfDay").value==8:
	
	myLogger.info("In if statement")
	system.util.execute(["C:\NAS_Backup_BatFiles\Bay1_Cust_Backup.bat"])

```

I get the log statements of in hour change and in if statement, but my batch file is not running. It does run with this same logic when inside a button. Any ideas why?

Using Ignition 7.9.10

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [February 18, 2019, 1:57pm UTC](https://forum.inductiveautomation.com/t/gateway-event-script-not-triggering-batch-file/22643/2 "2019-02-18T13:57:35Z")

</div>

Its likely that the service user that runs your gateway doesn’t have access to the batch file.

---

<div class="post-metadata">

**Author:** ![bkarabinchak.psi](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/bkarabinchak.psi/32/83567_2.png) [@bkarabinchak.psi](https://forum.inductiveautomation.com/u/bkarabinchak.psi)\
**Post date:** [February 18, 2019, 2:03pm UTC](https://forum.inductiveautomation.com/t/gateway-event-script-not-triggering-batch-file/22643/3 "2019-02-18T14:03:46Z")

</div>

We tested our client with the button that does successfully trigger this on the same computer that is hosting the gateway if that matters. How can I check who the service user is for the gateway/make changes to correct this?

---

<div class="post-metadata">

**Author:** ![Sanderd17](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/sanderd17/32/8735_2.png) [@Sanderd17](https://forum.inductiveautomation.com/u/Sanderd17)\
**Post date:** [February 18, 2019, 2:32pm UTC](https://forum.inductiveautomation.com/t/gateway-event-script-not-triggering-batch-file/22643/4 "2019-02-18T14:32:12Z")

</div>

On windows, the Ignition gateway is typically run as an unprivileged “service” user.

Using the “services” tool in Windows, you can alter the properties of the “Ignition” service, and choose to login as a different user with privileges.

This does mean that, from that point onwards, anyone who can execute code on the gateway (so anyone with designer access) can execute code as that user.

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [February 18, 2019, 2:35pm UTC](https://forum.inductiveautomation.com/t/gateway-event-script-not-triggering-batch-file/22643/5 "2019-02-18T14:35:20Z")

</div>

> [@bkarabinchak.psi](#):
>
> We tested our client with the button that does successfully trigger this on the same computer that is hosting the gateway if that matters.

That is insufficient. The gateway is a background service, and runs under its own account. Generally, you will find the relevant settings under "My Computer" ==\> "Manage" ==\> "Services".

---

<div class="post-metadata">

**Author:** ![bkarabinchak.psi](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/bkarabinchak.psi/32/83567_2.png) [@bkarabinchak.psi](https://forum.inductiveautomation.com/u/bkarabinchak.psi)\
**Post date:** [February 18, 2019, 3:10pm UTC](https://forum.inductiveautomation.com/t/gateway-event-script-not-triggering-batch-file/22643/6 "2019-02-18T15:10:57Z")

</div>

I went to services =\> Ignition =\> Properties =\> Log On, switched it from Local System Account to “This Account” and put in the administrator username and password for the computer. I am still getting the same issue. I don’t see the batch file attempt to open on the computer that is hosting the gateway. I still see log statements confirming I get into the if statement.

---

<div class="post-metadata">

**Author:** ![Kevin.Herron](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kevin.herron/32/7259_2.png) [@Kevin.Herron](https://forum.inductiveautomation.com/u/Kevin.Herron)\
**Post date:** [February 18, 2019, 3:19pm UTC](https://forum.inductiveautomation.com/t/gateway-event-script-not-triggering-batch-file/22643/7 "2019-02-18T15:19:37Z")

</div>

Just a guess, because Windows, but try running `cmd.exe /C C:\NAS_Backup_BatFiles\Bay1_Cust_Backup.bat` instead.

```auto
system.util.execute(["cmd.exe", "/C", C:\NAS_Backup_BatFiles\Bay1_Cust_Backup.bat"])

```

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [February 18, 2019, 3:44pm UTC](https://forum.inductiveautomation.com/t/gateway-event-script-not-triggering-batch-file/22643/8 "2019-02-18T15:44:49Z")

</div>

> [@bkarabinchak.psi](#):
>
> I don’t see the batch file attempt to open

You won't see it. It will run in the background. Have the batch file write to a log file of its own to see if it is running.

---

<div class="post-metadata">

**Author:** ![bkarabinchak.psi](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/bkarabinchak.psi/32/83567_2.png) [@bkarabinchak.psi](https://forum.inductiveautomation.com/u/bkarabinchak.psi)\
**Post date:** [February 18, 2019, 5:34pm UTC](https://forum.inductiveautomation.com/t/gateway-event-script-not-triggering-batch-file/22643/9 "2019-02-18T17:34:34Z")

</div>

Unfortunately that did not work either.

I am now trying to do it with strict python but that too is not working well.

```auto
from distutils.dir_util import copy_tree
from datetime import date

fromDirectory = "M:\Customer"
today = str(date.today())
toDirectory = "Z:\%s\Customer"%(today)
copy_tree(fromDirectory, toDirectory)

```

And I am getting the error

```auto
distutils.errors.DistutilsFileError: 
cannot copy tree 'M:\Customer': not a directory. 

```

I’ve tried it with `\\`,`//`,`/` as well and got the same error every time, so It is not an issue with the separator. Any ideas?

---

<div class="post-metadata">

**Author:** ![Kevin.Herron](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kevin.herron/32/7259_2.png) [@Kevin.Herron](https://forum.inductiveautomation.com/u/Kevin.Herron)\
**Post date:** [February 18, 2019, 5:57pm UTC](https://forum.inductiveautomation.com/t/gateway-event-script-not-triggering-batch-file/22643/10 "2019-02-18T17:57:26Z")

</div>

If you’re dealing with mapped drives you have to do some additional configuration so the gateway service can see them: [https://docs.inductiveautomation.com/display/DOC79/Mapping+a+Network+Drive](https://docs.inductiveautomation.com/display/DOC79/Mapping+a+Network+Drive)

Have you already done this?

---

<div class="post-metadata">

**Author:** ![jzngyi](https://avatars.discourse-cdn.com/v4/letter/j/a5b964/32.png) [@jzngyi](https://forum.inductiveautomation.com/u/jzngyi)\
**Post date:** [May 14, 2021, 10:06am UTC](https://forum.inductiveautomation.com/t/gateway-event-script-not-triggering-batch-file/22643/11 "2021-05-14T10:06:02Z")

</div>

Hi, I am using Ignition 8.0.15 and I am facing the same issue here. I created a button to trigger **system.util.execute([“C:\Users\Administrator\Desktop\test.bat”])** and it did run successfully. However when I use the same script in Gateway Event (Tag Change), it doesn’t work, and there’s no error log in the gateway.  
Is there anything I missed out?

---

<div class="post-metadata">

**Author:** ![JordanCClark](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jordancclark/32/83362_2.png) [@JordanCClark](https://forum.inductiveautomation.com/u/JordanCClark)\
**Post date:** [May 14, 2021, 10:21am UTC](https://forum.inductiveautomation.com/t/gateway-event-script-not-triggering-batch-file/22643/12 "2021-05-14T10:21:38Z")

</div>

A couple of things come to mind.

1. The user running the gateway service does not have access to the bat file.
2. It may need to run with elevated privileges. Make a shortcut to the .bat file, set the ‘Run as Administrator’ checkbox, and execute the shortcut.

---

<div class="post-metadata">

**Author:** ![Maria\_P](https://avatars.discourse-cdn.com/v4/letter/m/838e76/32.png) [@Maria\_P](https://forum.inductiveautomation.com/u/Maria_P)\
**Post date:** [February 9, 2022, 3:59pm UTC](https://forum.inductiveautomation.com/t/gateway-event-script-not-triggering-batch-file/22643/13 "2022-02-09T15:59:15Z")

</div>

Hi,  
I’m struggling with same problem. Trying to execute a batch file that is stored on ignition server from the gateway.  
We are now doing it by a scheduled task on windows, but we had some issues with that and want to integrate it all in ignition.  
Did you find a solution? A valid approach would also be to execute this file from a timer object, not the best solution but it would work for me.

---

<div class="post-metadata">

**Author:** ![mcolson1590](https://avatars.discourse-cdn.com/v4/letter/m/e8c25b/32.png) [@mcolson1590](https://forum.inductiveautomation.com/u/mcolson1590)\
**Post date:** [March 31, 2022, 4:57pm UTC](https://forum.inductiveautomation.com/t/gateway-event-script-not-triggering-batch-file/22643/14 "2022-03-31T16:57:29Z")

</div>

I created a shortcut in the same folder as the script itself. In the shortcut’s properties, I clicked on Advanced and checked the box for “Run as administrator”. My script then called the shortcut in lieu of the script.

def Main():  
system.util.execute([“cmd.exe”, “/C”, “C:\IgnitionScripts\MyScript.lnk”])
