I just checked to see if I have it read from a local drive's folder,
and change the security on this folder what will happen. Here is the
results (only tested on the problem scenario of running as a service):
When service is running as local system, canRead() returns true when it
has system account with read privileges. When system account does not
have read privileges, canRead() returns false.
When service is running as my network account, canRead() returns true
when my network account has read privileges. When it does not have read
privileges, canRead() returns false.
End result: it worked as I expected. But apparently this issue only
appears when dealing with mapped drives???
If this is the case, what is the recommended procedure for reading
Files from remote file servers? Assuming there is no per-se server
(like an FTP server or WWW server) on this remote file server....
Chris Harmon
ccjjharmon@gmail.com said:
>In a java bean, I am attempting to read a File object, which is a
>mapped drive (X:\\) on a Windows 2003 Server. What I am trying to do is
>read a file from this mapped drive.
[...]
>When I have Tomcat started as a Windows service, the .canRead() method
>returns false.
>
>When I have Tomcat started manually (command-line), the .canRead()
>method returns true. When I start it, I am logged into the server via
>Remote Desktop as my network account login.
Hmm.. just a thought (and I'm not too familiar with Windows), it
might well be that the drive mappings are only done when you do an
interactive login - so, when you're just running a service, the
drive is not mapped.
You might try using the UNC file paths (so,
\\servername\share\path\file.ext ).

Signature
Wolf a.k.a. Juha Laiho Espoo, Finland
(GC 3.0) GIT d- s+: a C++ ULSH++++$ P++@ L+++ E- W+$@ N++ !K w !O !M V
PS(+) PE Y+ PGP(+) t- 5 !X R !tv b+ !DI D G e+ h---- r+++ y++++
"...cancel my subscription to the resurrection!" (Jim Morrison)
ccjjharmon@gmail.com - 27 Mar 2006 13:52 GMT
Juha,
That was the first thing I came across in the newsgroups to try - using
the UNC path instead of the mapped drive. Unfortunately, I couldn't get
it to work at all... checking newsgroups again, I haven't tried using
runtime.exec() to make sure the drive is mapped...
But in all honesty, using the UNC path would be the more desirable
option in case the server (and/or share) changes I would rather be able
to dynamically deal with this change without needing to ensure the
mapped drive is changed also. Par for the course of this, it would be
*great* to know how I can provide the username and password to connect
to the UNC file path... but as far as I can tell, this isn't possible.
I believe it probably is some "quirk" that a Windows Java programmer
would quickly identify and know what they do to get past this... any
Windows Java programmers out there to chime in?
I am likely going to call a professor that is teaching an advanced Java
class I am taking (to get up to speed quicker on Java technology) - if
I get anywhere, I will post the news.
I am still hoping someone has some idea of what I can do though.
Chris
Chris Uppal - 27 Mar 2006 14:25 GMT
> But in all honesty, using the UNC path would be the more desirable
> option in case the server (and/or share) changes I would rather be able
> to dynamically deal with this change without needing to ensure the
> mapped drive is changed also. Par for the course of this, it would be
> *great* to know how I can provide the username and password to connect
> to the UNC file path... but as far as I can tell, this isn't possible.
I think you have to specify these as part of the service defintion, not of the
UNC filename.
Some stuff from MS:
http://msdn.microsoft.com/library/en-us/dllproc/base/service_user_accounts.asp
And this link may help (it's talking about a completely different service, but
the issues are the same):
http://www.monitorware.com/Common/en/FAQ/UNC-Path-Does-Not-Work-For-MWProducts.php
-- chris
ccjjharmon@gmail.com - 27 Mar 2006 15:05 GMT
I found it.... I had actually saved a link to a Sun forums thread about
this topic, but had forgot about it.... the thread is available at:
http://forum.java.sun.com/thread.jspa?threadID=695024&tstart=0
The key point? UNC works, but you have to use it with URI when
specifying new File(). What I was doing was using the File()
constructor using String as a parameter. What I needed to do was use a
URI object as a parameter! Someone posted some sample code that worked
for this guy, and it worked for me too. Here's the sample code that did
it:
URI myURI = new URI( "file://///server_one/images/unitMaps" );
File myFile = new File( myURI );
Newsgroups are just grand :) especially when posters include sample
code!! ;)
I still have Tomcat running as Local System, but I must specify the
share to have Everyone with sufficient access. Obviously to properly
secure the share, I would want to have a specific domain user created,
and have the share configured with the desired access, and run Tomcat
as this domain user... that's for later.
Cheers! And thanks for the comments.