How to share a folder with multiple users using java code?

I am trying to share a folder in java. I want to share a folder with several users. I use the following command:

net share sharefolder=<drive path> /GRANT:<username>,FULL

the above command shares the specified path folder with the username with FULL acess ie read and Write.

Can anyone help me out?

+4
source share
2 answers

For multiple users, you can use the following command in your Java code

net share sharefolder=<drivepath> /GRANT:<username>,Full /GRANT:<username>,Full

You can add as many users as you need. Thank,

+1
source

Use the java process to run your command:

String yourCommand = "net share sharefolder=<drive path> /GRANT:<username>,FULL";
Process p = Runtime.getRuntime().exec(yourCommand );

// To get the output of command            
BufferedReader stdInput = new BufferedReader(new InputStreamReader(p.getInputStream()));

BufferedReader stdError = new BufferedReader(new InputStreamReader(p.getErrorStream()));
+2
source

Source: https://habr.com/ru/post/1583974/


All Articles