javabee
javabee

Reputation: 85

java check for admin rights on a specific location

I am developing an application which installs an exe file on a particular directory on either local or remote using java. Is there anyway to check whether that remote location has admin rights or is that an installable location using java?

Thanks in advance.

Upvotes: 3

Views: 598

Answers (1)

MadProgrammer
MadProgrammer

Reputation: 347314

There are better ways to achieve this in Java 7, check out File I/O (Featuring NIO.2) for more details (in particular Checking a File or Directory, but I don't (yet) have experience with this API.

Under Java 6 and below we had to do some hoop jumping (especially under Windows 7 and UAC)...

You can use File#canWrite to check to see if the destination path is writable, this will, how ever, return true under Windows 7, even when the UAC won't let you...much to our horror...

We wrote a simple utility method that basically checks File#canWrite, if it was true, it wrote a temp file, with a simple String and checked to see if it existed (File#exists) and that the contents was what we wrote was the same. If that worked, then were sure we could write to the location...

(Note the paranoia, we spent 2 weeks running tests to find the problem and come up with a solution we could trust)

Upvotes: 5

Related Questions