Gateway Script can't open directory

The following code is in a Global Script Module.
It works fine when called from a button event handler script, but generates an error when run in a gateway timer script. Any ideas what’s happening here?

sPath = "P:\\"
for sFileName in os.listdir(sPath):
  # do Something with each file

The error generated in wrapper.log is

OSError: [Errno 0] No such directory: P:\

I know the directory exists; also as I mentioned it works fine from a button event handler.

Is your client running on the same machine as the gateway? The P drive might be a mapped drive that didn’t make it to all of the computers. You might want to try something like ‘’\MyComputerName\SharedFolder" instead.

I tried that and it gives the same results.

In answer to your question, yes the client is running on the same machine as the gateway.

If I copy some of the source files to c:\ and use that in the script, it works fine both from the gateway and the client.
However “\servername\sharename” or “P:” only works from the client.

It’s a strange one.

It has to do with permissions. When you run the script from the client it runs under the account you are logged in as. When you run a script in the gateway it runs on the gateway and uses the local system account. That mapped drive doesn’t exist for the local system account.

You can change which account the Ignition Windows service runs under by going to the Services Control Panel. It is under Control Panel > Administrative Tools > Services. Right click on the Ignition service and select Properties. Click on the Log On tab and change it from the local system account to this account (which is a valid domain account that has access to the shared directory). Once you do that restart Ignition and change your script to access “\MyComputerName\SharedFolder” like Robert suggested.

Let us know if you continue to have issues.

Good news & bad news:

Good news: That does indeed fix the problem. I switched to the local administrator account and it can see the directory and read files from it with no problem.

Bad news: It breaks the OPC Server connection to KepServer software we have running to interface to PLCs.

I have reverted back to the original account to get the communications going again.

Any thoughts on what might be happening here?

Update:

I found this on an OPC forum:

[code]When you connect from one applicaiton to anther and they are running under different user accunts this is treated the same as connect to a server running on another PC. My suggestion is to configure DCOM permistions at a minimum for System, local users and admins. If you are on a domain then domain users and admins. Also if go to Tools | Options in the server and uncheck use DCOM configuration utility to set security" on the OPC Settings Tab this will relax the servers security settings for local connections.

Fred Loveless
Kepware Technologies[/code]

I’ll try to adjust DCOM security and see what happens. However, it’s now almost 5pm on Friday here in Ireland, so it will have to wait until next week - now is not the time to be making system configuration changes!

You also need to change the log on settings for the Kepware OPC Server service as well. If they are both the same you shouldn’t have any problems.

I have changed the logon for both services and all is now working.
Many thanks.