# File writing code

**URL:** <https://forum.inductiveautomation.com/t/file-writing-code/21372>\
**Category:** Ignition\
**Created:** [December 12, 2018, 3:38pm UTC](https://forum.inductiveautomation.com/t/file-writing-code/21372 "2018-12-12T15:38:40Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![aelgezabal](https://avatars.discourse-cdn.com/v4/letter/a/f19dbf/32.png) [@aelgezabal](https://forum.inductiveautomation.com/u/aelgezabal)\
**Post date:** [December 12, 2018, 3:38pm UTC](https://forum.inductiveautomation.com/t/file-writing-code/21372/1 "2018-12-12T15:38:40Z")

</div>

what difference between executing a file handwriting code event handlers or as event script (Gateway)? With the first one he writes with the second he says denied access  
As you can see, he does not speak very well. I’m sorry.

---

<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:** [December 12, 2018, 3:42pm UTC](https://forum.inductiveautomation.com/t/file-writing-code/21372/2 "2018-12-12T15:42:56Z")

</div>

Code running in event handlers is running in the scope of the Client or Designer, so it’s running on whatever machine the Client is running on, and with the permissions of whatever user launched the Client.

Code running on a Gateway tag change or event script runs on the gateway machine, under the user that launched the Ignition service.

---

<div class="post-metadata">

**Author:** ![oscar.salcedo](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/oscar.salcedo/32/11019_2.png) [@oscar.salcedo](https://forum.inductiveautomation.com/u/oscar.salcedo)\
**Post date:** [December 12, 2018, 3:50pm UTC](https://forum.inductiveautomation.com/t/file-writing-code/21372/3 "2018-12-12T15:50:02Z")

</div>

@aelgezabal I’ll translate @Kevin.Herron 's message (más o menos 🙂):

“El código que corre en “event handlers” se ejecuta en el cliente o en el entorno de desarrollo, asi que solo tiene acceso a la maquina donde el cliente esta corriendo, y con los permisos que tenga el usuario que ejecutoó ese cliente.  
El código que corre en el servidor se ejecuta directamente en la maquina que alberga el servidor, por lo cual solo tendría acceso a los recursos del servidor”

O sea, si quieres que el cliente sea quien escriba el fichero (a disco local o a una carpeta compartida en cualquier otro servidor/PC), tienes que asegurarte de que el usuario que esta lanzando el cliente en esa maquina (el usuario que esta logueado en esa maquina) tenga permisos para escribir en ese directorio.  
La misma regla aplica a codigo ejecutando en el servidor: el usuario bajo el que se ejecuta el servcio de ignition tiene que tener permisos sobre esa carpeta local o remota.

Espero que esté algo mas claro.

Oscar

---

<div class="post-metadata">

**Author:** ![aelgezabal](https://avatars.discourse-cdn.com/v4/letter/a/f19dbf/32.png) [@aelgezabal](https://forum.inductiveautomation.com/u/aelgezabal)\
**Post date:** [December 13, 2018, 7:07am UTC](https://forum.inductiveautomation.com/t/file-writing-code/21372/4 "2018-12-13T07:07:48Z")

</div>

153/5000  
Thank you that has to be. I have done the test but I did not start the Ignition service and I have to search for it. Thank you Oscar and Kevin.

Gracias eso tiene que ser. He hecho la prueba pero no me arrancaba el servicio de Ignition y tengo que rebuscar porque. Muchas gracias Oscar y a ti Kevin

---

<div class="post-metadata">

**Author:** ![aelgezabal](https://avatars.discourse-cdn.com/v4/letter/a/f19dbf/32.png) [@aelgezabal](https://forum.inductiveautomation.com/u/aelgezabal)\
**Post date:** [December 21, 2018, 7:47am UTC](https://forum.inductiveautomation.com/t/file-writing-code/21372/5 "2018-12-21T07:47:11Z")

</div>

Hi all  
The Ignition service is started with a local administrator user. And we want it to be written to another server, for which we have created a domain user with permissions to write, but the service does not start with this user. Is the change of user made? Or how do I do it without changing the user?

---

<div class="post-metadata">

**Author:** ![oscar.salcedo](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/oscar.salcedo/32/11019_2.png) [@oscar.salcedo](https://forum.inductiveautomation.com/u/oscar.salcedo)\
**Post date:** [December 21, 2018, 1:30pm UTC](https://forum.inductiveautomation.com/t/file-writing-code/21372/6 "2018-12-21T13:30:04Z")

</div>

A couple of options:

1. You can change the Ignition service to execute as the domain user that has access to the file share on the other server
2. You can map a drive from the gateway configuration file (ignition.conf). Add these entries:

> wrapper.share.4.location=\host\share  
> wrapper.share.4.target=W:  
> wrapper.share.4.type=DISK  
> wrapper.ntservice.account=domain\user  
> wrapper.ntservice.password=password  
> wrapper.share.4.shutdown.unmap=TRUE  
> wrapper.share.4.startup.max\_retries=3  
> wrapper.share.4.startup.retry\_interval=10

You can use the two entries below (instead of the "wrapper.ntservice.account" entries above) if the target machine is not a domain member. The user will be a local user on the target machine that has access to the share  
wrapper.share.4.account=user  
wrapper.share.4.password=password

See the docs for more details: [Mapping a Network Drive - Ignition User Manual 7.9 - Ignition Documentation](https://docs.inductiveautomation.com/display/DOC79/Mapping+a+Network+Drive)

Let me know if you need any more help on this.

Oscar.

---

<div class="post-metadata">

**Author:** ![ryanjmclaughlin](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/ryanjmclaughlin/32/4318_2.png) [@ryanjmclaughlin](https://forum.inductiveautomation.com/u/ryanjmclaughlin)\
**Post date:** [December 21, 2018, 1:49pm UTC](https://forum.inductiveautomation.com/t/file-writing-code/21372/7 "2018-12-21T13:49:11Z")

</div>

I know adding the shares to the wrapper method is common, but we have found it significantly easier (and less maintenance) to simply run Ignition under a common service account. Ex: DOMAIN\IgnitionService Then in our ActiveDirectory and shares just grant access to this account as required. From any scripts in Ignition we always reference files/shares using the fully qualified UNC paths. Ex. \server\share\folder\file.txt

---

<div class="post-metadata">

**Author:** ![oscar.salcedo](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/oscar.salcedo/32/11019_2.png) [@oscar.salcedo](https://forum.inductiveautomation.com/u/oscar.salcedo)\
**Post date:** [December 21, 2018, 4:36pm UTC](https://forum.inductiveautomation.com/t/file-writing-code/21372/8 "2018-12-21T16:36:52Z")

</div>

I agree 100%.  
I just wanted to throw the second option out there; there are lot of manufacturing environments out there where the OT supervisory systems are not integrated fully into IT, hence the only feasible way is to map a drive as a different user.

---

<div class="post-metadata">

**Author:** ![aelgezabal](https://avatars.discourse-cdn.com/v4/letter/a/f19dbf/32.png) [@aelgezabal](https://forum.inductiveautomation.com/u/aelgezabal)\
**Post date:** [December 26, 2018, 9:51am UTC](https://forum.inductiveautomation.com/t/file-writing-code/21372/9 "2018-12-26T09:51:52Z")

</div>

Hello  
I added to Ignition.conf, at the end of the file and keeps saying access denied  
wrapper.share.4.location=\biz-fsw2\geometria\UBICACION\_DMOs\_PARA\_IMPORTAR\_BASE\_DATOS\ImportRoot  
wrapper.share.4.target=W:  
wrapper.share.4.type=DISK  
wrapper.ntservice.account=es\Ignition  
wrapper.ntservice.password=\*\*\*\*\*\*  
wrapper.share.4.shutdown.unmap=TRUE  
wrapper.share.4.startup.max\_retries=3  
wrapper.share.4.startup.retry\_interval=10

It´s Good

---

<div class="post-metadata">

**Author:** ![oscar.salcedo](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/oscar.salcedo/32/11019_2.png) [@oscar.salcedo](https://forum.inductiveautomation.com/u/oscar.salcedo)\
**Post date:** [December 26, 2018, 1:19pm UTC](https://forum.inductiveautomation.com/t/file-writing-code/21372/10 "2018-12-26T13:19:52Z")

</div>

> wrapper.share.4.location=\biz-fsw2\geometria\

Should that be "\biz-fsw2\geometria" ? (two backslashes)

Cheers,

Oscar.

---

<div class="post-metadata">

**Author:** ![aelgezabal](https://avatars.discourse-cdn.com/v4/letter/a/f19dbf/32.png) [@aelgezabal](https://forum.inductiveautomation.com/u/aelgezabal)\
**Post date:** [December 27, 2018, 7:40am UTC](https://forum.inductiveautomation.com/t/file-writing-code/21372/11 "2018-12-27T07:40:52Z")

</div>

I had not read this ![](https://us1.discourse-cdn.com/inductiveautomation/original/2X/b/be3d5a6cc5d121bdf0710c0626bd70cd561616d9.png)  
I have Ignition 7.2.6 is it not possible to do this?

regards  
Ander
