0

I am trying to run the "net use" command by invoking it using process builder. As I pass the password to the OutputStream using PrintWriter it fails with the following error : System error 1219 has occurred. Multiple connections to a server or shared resource by the same user, using more than one user name, are not allowed. Disconnect all previous connections to the server or shared resource and try again.

I have checked the username, password and the command, by running it manually. Its working fine

The code snippet :

ProcessBuilder pb = new ProcessBuilder("net","use","\\\\<SERVERNAME>\\<SharedLocation>","/USER:<username>","*");
Process p = pb.start();
OutputStream out = p.getOutputStream();
PrintWriter writer = new PrintWriter(out);      
writer.println("<pwd>".toCharArray());
int exitCode = p.waitFor();     
System.out.println("Exit Code :"+ exitCode);
Anuj
  • 1
  • 3

1 Answers1

0

A couple of suggestions:

  • Run net use * /delete /y as your first step to remove all connections before you start. You can also try removing specific connections.
  • Use a pure Java solution instead of net use -- see https://stackoverflow.com/a/208896/4803
Community
  • 1
  • 1
RedGreenCode
  • 2,195
  • 1
  • 25
  • 33
  • Thanks for the comment. I used `net use */delete /y` to remove all the connections which also removed the connection for which I was trying `net use`. Now it is failing with a different error : _System error 86 has occurred. The specified network password is not correct._ But I when manaully run the command from cmd with the same password it passes successfully. Is my way of passing the password incorrect? – Anuj Oct 28 '14 at 18:09
  • Your code works for me. There are some other code samples in http://stackoverflow.com/questions/208839/how-can-i-mount-a-windows-drive-in-java?lq=1 that you could try. – RedGreenCode Oct 28 '14 at 18:54
  • Have you use the same way to pass the password that I have used in the code?Becuase I tried running the code from my friend's system.I am still getting the same error. – Anuj Oct 29 '14 at 07:03