File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Java in General and the fly likes Access Network drive through Java Application running as a service Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Access Network drive through Java Application running as a service" Watch "Access Network drive through Java Application running as a service" New topic
Author

Access Network drive through Java Application running as a service

jai balu
Greenhorn

Joined: Sep 04, 2008
Posts: 9
Hi all,

In the java Program i try to create a file in network drive and it works fine when it run as a java application.When i try to run the same program as an window service it not able to create a file.

I used Java wrapper service for the window service and used this reference http://www.coderanch.com/t/328372/java/java/Map-drive-access-through-Java

I installed the service and create a new user account with the adminstative rights and add user in start-->Administative tool-->Local security policy-->User Right Assignment-->Log on service
Then Start-->Administative tool-->Service seleted my service and right click properties and went to Log on Tab.In Log On Tab selected "This account" and selected the created user account and given password for the users.

Now i started the service, it started without any error.But when i try to access the network drive it throws Exception like this:
INFO | jvm 1 | 2008/08/26 14:35:52 | java.io.IOException: An unexpected network error occurred
INFO | jvm 1 | 2008/08/26 14:35:52 | at java.io.WinNTFileSystem.createFileExclusively(Native Method)
INFO | jvm 1 | 2008/08/26 14:35:52 | at java.io.File.createNewFile(File.java:850)

i have given the UNC Path for file creation and the mapped network drive is accessible from windows explorer.

Please help me to create the file in the network drive when the program is running as a service.

Thanks,
Jayam
Joe Ess
Bartender

Joined: Oct 29, 2001
Posts: 8876
    
    8

Welcome to the JavaRanch.
Does the user you created have access to the network drive? Can you log in as the new user and open the drive in Explorer?
I just had a similar problem. Our network uses Active Directory so the service had to run as a "real" user account in order to access a shared drive.


"blabbing like a narcissistic fool with a superiority complex" ~ N.A.
[How To Ask Questions On JavaRanch]
jai balu
Greenhorn

Joined: Sep 04, 2008
Posts: 9
I logged into the system with new user and mapped the network drive with network username and password and able to access the network drive. But as a service i could not access the network drive.
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19680
    
  19

Is your code also using the network mapping, or the actual network address (\\servername\share\folder)?

Because the former will not work since there is no mapping without a user logged in.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
jai balu
Greenhorn

Joined: Sep 04, 2008
Posts: 9
I am getting the following exception also :
java.io.IOException: The specified network password is not correct
INFO | jvm 1 | 2008/09/04 18:35:26 | at java.io.WinNTFileSystem.createFileExclusively(Native Method)
INFO | jvm 1 | 2008/09/04 18:35:26 | at java.io.File.createNewFile(File.java:850)
INFO | jvm 1 | 2008/09/04 18:35:26 | at

Which password is this user account password or network password because no where we are giveing network username/password.
jai balu
Greenhorn

Joined: Sep 04, 2008
Posts: 9
My code is using the actual address like this \\TRDOUG\_Home_\
Ove Lindström
Ranch Hand

Joined: Mar 10, 2008
Posts: 326

Does your service run under a user, the administrator or as system?

If it is the last, you can not access resources outside the machine.
jai balu
Greenhorn

Joined: Sep 04, 2008
Posts: 9
i am running the service as user which is having the adminstative rights.

if i log into the system as user and run service as user i am getting the following error:
java.io.IOException: The specified network password is not correct
INFO | jvm 1 | 2008/09/04 18:35:26 | at java.io.WinNTFileSystem.createFileExclusively(Native Method)
INFO | jvm 1 | 2008/09/04 18:35:26 | at java.io.File.createNewFile(File.java:850)

If i run the service as local system it is giving the following exception : Access denined to the network resouces
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19680
    
  19

I think the message is quite clear: you seem to have mistyped your password.
jai balu
Greenhorn

Joined: Sep 04, 2008
Posts: 9
My network drive was disconnected before so i got this exception:
java.io.IOException: The specified network password is not correct
INFO | jvm 1 | 2008/09/05 14:22:34 | at java.io.WinNTFileSystem.createFileExclusively(Native Method)
INFO | jvm 1 | 2008/09/05 14:22:34 | at java.io.File.createNewFile(File.java:850)

After connecting to the network drive i am getting the following exception:
va.io.IOException: An unexpected network error occurred
INFO | jvm 1 | 2008/09/05 14:28:03 | at java.io.WinNTFileSystem.createFileExclusively(Native Method)
INFO | jvm 1 | 2008/09/05 14:28:03 | at java.io.File.createNewFile(File.java:850)
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19680
    
  19

Can you create a file with the same name in Windows Explorer if you are logged in as the same user?
jai balu
Greenhorn

Joined: Sep 04, 2008
Posts: 9
yes i can create file with the same name in network drive from windows explore and from java console application also i am able to create the file in network drive.
jai balu
Greenhorn

Joined: Sep 04, 2008
Posts: 9
I conclude what are thing i have done

I am using the Java wrapper service (3.2.3) for window service. In my java server program i try to create file in network drive, as a console application it is working fine and creating the file in network drive.But when the application run as a window service it is throwing an exception as follow's :
INFO | jvm 1 | 2008/08/26 14:35:52 | java.io.IOException: An unexpected network error occurred
INFO | jvm 1 | 2008/08/26 14:35:52 | at java.io.WinNTFileSystem.createFileExclusively(Native Method)
INFO | jvm 1 | 2008/08/26 14:35:52 | at java.io.File.createNewFile(File.java:850)

These are thing i followed
1. Created a new user account(for example :TestAccount) with Adminstrator privilage.
2.Made an entry of the new user account(TestAccount) in Administative tool-->Local security policy-->User Right Assignment-->Log on service.
3. Installed the service
4.Administative tool-->Service seleted my service and right click properties and went to Log on Tab.In Log On Tab selected "This account" and selected the created new user account(TestAccount) and given password for the users.
5.Started the service.
6.The network drive is mapped properly and connected to the network
7.Logged into the system using newly created user(TestAccount).
8.I can able to create file in the network drive from windows explore/through the java console application with same/different filename

The service started sucessfully without any exception.Then my application startup and try to create an file in the network drive, but it is throwing an exception like this:
INFO | jvm 1 | 2008/08/26 14:35:52 | java.io.IOException: An unexpected network error occurred
INFO | jvm 1 | 2008/08/26 14:35:52 | at java.io.WinNTFileSystem.createFileExclusively(Native Method)
INFO | jvm 1 | 2008/08/26 14:35:52 | at java.io.File.createNewFile(File.java:850)

Please help me to resolve this issue
Joe Ess
Bartender

Joined: Oct 29, 2001
Posts: 8876
    
    8

Read through this discussion on the Java wrapper service mailing list. It has several good troubleshooting points. Failing that, try posting on the user mailing list itself.
jai balu
Greenhorn

Joined: Sep 04, 2008
Posts: 9
Thanks..The link you have given resolved my issuse.

The problem was the username of my local useraccount and username of my network is different.

Solution is username of local useraccount and username of network should be same ,password may be different.

Once again thanks for your replies.

jai
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Access Network drive through Java Application running as a service