• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Access Network drive through Java Application running as a service

 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 https://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
 
Bartender
Posts: 9626
16
Mac OS X Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
jai balu
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Sheriff
Posts: 22781
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
jai balu
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
My code is using the actual address like this \\TRDOUG\_Home_\
 
Ranch Hand
Posts: 326
Android Mac OS X Firefox Browser
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 22781
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think the message is quite clear: you seem to have mistyped your password.
 
jai balu
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 22781
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can you create a file with the same name in Windows Explorer if you are logged in as the same user?
 
jai balu
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 9626
16
Mac OS X Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
girl power ... turns out to be about a hundred watts. But they seriuosly don't like being connected to the grid. Tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic