aspose file tools*
The moose likes I/O and Streams and the fly likes Writing a file in Mapped Network drive using java running as Windows service Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » I/O and Streams
Bookmark "Writing a file in Mapped Network drive using java running as Windows service" Watch "Writing a file in Mapped Network drive using java running as Windows service" New topic
Author

Writing a file in Mapped Network drive using java running as Windows service

Balaji Soundarajan
Ranch Hand

Joined: Jan 23, 2009
Posts: 59
Hi,

We are trying to create a file in mapped network drive (Z:\VOL3) using java.The file is successfully created in standalone java application.But if the same java application ruuning as windows service then its throwing "system cannot find the path specified" error.
We have tried like File f=new File("Z:\VOL3");

Please help us resolve this issue.

Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19720
    
  20

That's because by default, network mappings are user-specific. That means that the user that is running the service (usually "Local System") does not know about your Z "drive".


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Balaji Soundarajan
Ranch Hand

Joined: Jan 23, 2009
Posts: 59
How to achieve this?
Is there any way to change something to access the neetwork drive thru application running as service?

Please let us your comments.
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19720
    
  20

http://stackoverflow.com/questions/182750/how-to-map-a-network-drive-to-be-used-by-a-service
http://www.google.com/search?client=opera&rls=en&q=map+network+drive+for+local+system+user&sourceid=opera&ie=utf-8&oe=utf-8
Hobie Orris
Greenhorn

Joined: Dec 30, 2009
Posts: 1
I am experiencing the same problem. Another poster on this site got it working by
1. Changing the service credentials to user (system accounts don't have network privileges)
2. Changing the file path you are trying to access to a UNC (I changed mine from Z: to \\billthecat\store for example)

These were not sufficient for me. When I switched the service account to 'Admin' from 'LocalSystem' I got a pop-up telling me that Admin was granted the 'run as system service' privilege, but I am skeptical. I am using XP Home and I can't actually examine my real privileges. I am wondering if I need a different version of Windows to make this work.
Carey Evans
Ranch Hand

Joined: May 27, 2008
Posts: 225

Running as a user (or as NetworkService) may only work when both computers are in the same domain, which won't be the case with XP Home.

A more complicated alternative is JCIFS, which doesn't use java.io.File, but would let you supply your own network username and password.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Writing a file in Mapped Network drive using java running as Windows service