简体   繁体   中英

Access Files Remotely on Windows using a Windows Service

I have a Windows service that executes a .bat file. This .bat file executes some Sava code that reads some files' information. The files I need to access are not in the same machine that the service is running. So I should access them using a mapping like G:\\ .

Even if the files exist on G:\\ when I run the service, File exists() and File canRead() always return false.

If I execute the .bat manually, everything works great, but I need to execute it using a service.

The service is running with a user that has permissions to read all files on this G:\\ mapping.

Does anyone have a clue as to what can be wrong? Why can't I access these remote files, when running as a Windows service?

The OS in question is Windows XP .

The problem usually is that the user running the service does not have the same G: drive as well as the same access.

I suggest you log in as the user running the service and see what that user sees.

Drive mappings aren't shared between sessions, and service sessions don't get drive mappings reestablished automatically the way interactive sessions do. You should put a net use command in the batch file to explicitly establish the drive mapping in the service session.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM