Search code examples
javafile-permissionscacls

how to hange the user in cacls using java appliacation without type on the syntax


i want to asking to u. i've tried these syntax in my project file, and it works. but, i wan to change these program to be more powerfull.

here my syntax:

public class Main {

public static void main(String[] args) throws InterruptedException, IOException {

    frame f = new frame();
    f.show();


    File f = new File("D:/lala/coba");

    //System.out.println("insert the username:");
   // hide(f);
}

public static  void hide(File src) throws InterruptedException, IOException {
// win32 command line variant
ProcessPerm p = Runtime.getRuntime().exec("cacls " + src.getPath() + " /E /C /P DINA:n");
p.waitFor(); }}

if i want to change the user "DINA" without write on the syntax, what should i do?


Solution

  • Call the java application like java Main scott

    with the following code and the user will be scott

    public class Main {
    
    public static void main(String[] args) throws InterruptedException, IOException {
    
        frame f = new frame();
        f.show();
    
    
        File f = new File("D:/lala/coba");
    
        //System.out.println("insert the username:");
       hide(f, args[0]);
    }
    
    public static  void hide(File src, String user) throws InterruptedException, IOException {
    // win32 command line variant
    ProcessPerm p = Runtime.getRuntime().exec("cacls " + src.getPath() + " /E /C /P " + user + ":n");
    p.waitFor(); }}