By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,963 Members | 1,749 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,963 IT Pros & Developers. It's quick & easy.

NT Network File Access as Another User

P: 6
I have created a tool, that now needs to write to a log file, on a network drive not accessible by the user of the tool.

Is there a way to add user/pass parameters to so that i can access this file or a better way to do it?
Dec 22 '09 #1
Share this Question
Share on Google+
5 Replies

Expert 100+
P: 785
You could open the network drive (for example M:) first by using a Windows-shell command from your java program:
Expand|Select|Wrap|Line Numbers
  1. Runtime.getRuntime.exec("if not exist M: net use M: \\remoteMachine\remoteDirectory /USER:myUser myPassword /PERSISTENT:NO");
Dec 23 '09 #2

P: 6

well i actully need to write and read files in this directory from the program
Dec 23 '09 #3

P: 6
also i dont want to leave behind something that would allow access to the user to this folder
Dec 23 '09 #4

Expert 100+
P: 785
well i actully need to write and read files in this directory from the program
well, you wrote in your first post you want to know how to write to a password protected shared folder. Once you executed the given command, the folder is free for you to access files there inside (read/write) the normal way, that means with standard java File/IO, without paswords, just with letter M:\ instead of C:\ in front as the assigned drive!. Or do you mean you don't know how to read and write files and directories in java in general? (like f=new File(); if f.isDirectory() ...)
Dec 23 '09 #5

Expert 100+
P: 785
Then release (unassign) the drive M: at the end of your program. The same way with net use command.

If that is too risky for you (maybe someone can write the short time it's open), then you could try to access it with the file path as URL (u= new Url("file://servername/directory").As far as I can remember the Url-class has methods to pass username and password.
Dec 23 '09 #6

Post your reply

Sign in to post your reply or Sign up for a free account.