Access network drive through JAVA (while windows XP screen locked)

I am trying access a shared network drive through JAVA. If I am logged in to Windows XP, it works fine. I am using Eclipse. When I create jar file and automate the process for the times that my desktop is locked, it gives "Access is denied" exception.

I looked to the knowledge base, but couldn't find my solution.

The error is: \\serverName\FileName.csv (Access is denied)

How can I get around this error? Is there a way to login to a network drive as if I am logging in to a JDBC drive?
package utilities;
import javax.mail.MessagingException;
public class CopyFile {
	protected String myFromFileDirectory;
	protected String myDestinationFileDirectory;
	public CopyFile(String fromFileName,String toFileName) throws MessagingException{
		Email em = new Email();
		myFromFileDirectory = fromFileName;
		myDestinationFileDirectory = toFileName;
		 try {
			 File fromFile = new File(fromFileName);
			 File toFile = new File(toFileName);
			 FileInputStream from = null;
			 FileOutputStream to = null;
			 from = new FileInputStream(fromFile);
			 to = new FileOutputStream(toFile);
			 byte[] buffer = new byte[4096];
			 int bytesRead;
			 while ((bytesRead = != -1)
			 to.write(buffer, 0, bytesRead); // write	  	
		  } catch (IOException e) {
		    em.postExceptionToMe("", "File Transfer Exception","", e);
	public static void main(String[] args) {
		String from="D:\\FileName.csv";
		String to="\\\\serverName\\FileName.csv";
		try {
			new CopyFile(from,to);
		} catch (MessagingException e) {

Open in new window

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

String to="\\\\serverName\\FileName.csv"  ... you most likely mean

String to="\\\\serverName\\SHARENAME\FileName.csv"

You have to specify a sharename when referencing a UNC path...
sorry, missed the second backslash between sharename and filename.csv

String to="\\\\serverName\\SHARENAME\\FileName.csv"
Are you happy to view / edit the registery ?


from 1 to 0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Determine the Perfect Price for Your IT Services

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden with our free interactive tool and use it to determine the right price for your IT services. Download your free eBook now!

nicoleheritageAuthor Commented:
Sorry about that, I do have a SHARENAME in my code. It looks like what you have posted. Problem continues.

When you automate it, what are you using?  if it's scheduled tasks, you might want to go to Properties and on the Task tab at Run as: make sure your username is in there, then click Set password... and type in your password.
nicoleheritageAuthor Commented:
to edster9999:

"restrictanonymous" was 0, so I didn't change it, but I had another entry called "restrictanonymoussam". It was 1, I changed that one also  to 0.

And now it works!!!


Thank you so much edster9999!!!

You are welcome.

You can also get round this by specifing a login and going that way - then it will work without updating that.
It is a security feature to lock down anonymous attachments while the screen saver is active and the system is locked.
I agree... specifying a login is probably the better option.  There's a reason why that's set in the registry, and unsetting it could potentially open your computer up to attack.
nicoleheritageAuthor Commented:
Then, how can I specify a login?
Not really.... When you are logged in like you are now you have shares that can be read by 'anonymous'.  
I've never really seen why you would want this more secure when logged off or on screen saver.
If something is open all day what good would it be to lock it while you are out on your lunch break.  If someone wants to access it they can do it in an hour.

(just my thoughts)
Good info... thanks edster9999
I'm not a java expert so maybe someone else could tell nicoleheritage (author) how to specify username (and password) in this type of transaction.
nicoleheritageAuthor Commented:
to edster9999:

Please see question titled:

"Access network drive through JAVA (when logged off)"

It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Server Software

From novice to tech pro — start learning today.