Kunal Varpe
Kunal Varpe

Reputation: 463

How to share folder to multiple users using java code?

I am trying to share the folder programatically in java. I want to share the folder to multiple users. I use the following command:

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

the above command share the given drive path folder with the username with FULL acess i.e read and Write.

Can anyone please help me out?

Upvotes: 2

Views: 1274

Answers (2)

Sagar Mehta
Sagar Mehta

Reputation: 455

For multiple users you may use following command in your java code

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

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

Upvotes: 1

Sumit Singh
Sumit Singh

Reputation: 15896

Use 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()));

Upvotes: 2

Related Questions