NT Network File Access as Another User

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • intriken
    New Member
    • Feb 2007
    • 6

    NT Network File Access as Another User

    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 java.io.File so that i can access this file or a better way to do it?
  • chaarmann
    Recognized Expert Contributor
    • Nov 2007
    • 785

    #2
    You could open the network drive (for example M:) first by using a Windows-shell command from your java program:
    Code:
    Runtime.getRuntime.exec("if not exist M: net use M: \\remoteMachine\remoteDirectory /USER:myUser myPassword /PERSISTENT:NO");

    Comment

    • intriken
      New Member
      • Feb 2007
      • 6

      #3
      Originally posted by chaarmann
      You could open the network drive (for example M:) first by using a Windows-shell command from your java program:
      Code:
      Runtime.getRuntime.exec("if not exist M: net use M: \\remoteMachine\remoteDirectory /USER:myUser myPassword /PERSISTENT:NO");


      well i actully need to write and read files in this directory from the program

      Comment

      • intriken
        New Member
        • Feb 2007
        • 6

        #4
        also i dont want to leave behind something that would allow access to the user to this folder

        Comment

        • chaarmann
          Recognized Expert Contributor
          • Nov 2007
          • 785

          #5
          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() ...)

          Comment

          • chaarmann
            Recognized Expert Contributor
            • Nov 2007
            • 785

            #6
            Originally posted by intriken
            also i dont want to leave behind something that would allow access to the user to this folder
            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.

            Comment

            Working...