Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 367
javabee Avatar asked Jan 28 '26 01:01

javabee


1 Answers

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)

like image 113
MadProgrammer Avatar answered Jan 30 '26 15:01

MadProgrammer



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!