Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Permission denied when trying Runtime.exec() (cacls command)

807589Jul 31 2008 — edited Aug 1 2008
Hi,

I've made a simple app in the NetBeans IDE to make your usb stick a little safer. It uses the windows cacls command to edit acls. This would deny access to a folder.
There is only one problem.

On a normal user account, it returns the error: Permission denied. (or something, I translated it from Dutch)

I don't know why I get this error. At the command prompt, normal user do have permission to run the cacls command.
My app doesnt seem to have the rights to execute this command.

cacls function:
    private void unlock(String file,String user){
    String s = null;

        try {
            
            
            String[] command = {"cacls" , file , "/E" , "/G" , user + ":F" };
            
            Process p = Runtime.getRuntime().exec(command);
            
            BufferedReader stdInput = new BufferedReader(new 
                 InputStreamReader(p.getInputStream()));

            BufferedReader stdError = new BufferedReader(new 
                 InputStreamReader(p.getErrorStream()));

            // read the output from the command
            
            while ((s = stdInput.readLine()) != null) {
                System.out.println(s);
            }
            
            // read any errors from the attempted command
            
            while ((s = stdError.readLine()) != null) {
                System.out.println(s);
            }
            
        }
        catch (IOException e) {
            System.out.println("Exception: ");
            e.printStackTrace();
        }
    }
This function gives permission to the file 'file' for the user/usergroup 'user'.

Running as administrator isn't really an option. This app is ment to be used at school and I don't think I'm gonna get the admin password..
Somebody help me please :D

Thanks in advance
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Aug 29 2008
Added on Jul 31 2008
25 comments
2,966 views