Gateway Event Script not triggering batch file

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 -

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

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

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?

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.

1 Like

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

1 Like

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.

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

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

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.

Unfortunately that did not work either.

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

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

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?

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

Have you already done this?

1 Like

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?

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.