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);
1
  • Able to solve this case ? I am also facing the same issue. Jan 30, 2023 at 11:03

2 Answers 2

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
3
  • 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, 2014 at 18:09
  • Your code works for me. There are some other code samples in stackoverflow.com/questions/208839/… that you could try. Oct 28, 2014 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, 2014 at 7:03
0

I literally just signed up on stackoverflow because I had the exact same issue and solved it after spending hours and hours of trial and error.

The solution for me was adding a "\" (respectively "\\" in java code) right before the username.

This is what worked for me:

String[] cmdCommand = new String[]{"net", "use", "\\\\" + pcSystem.getIpAddress() + "\\c$", "/user:\\" + pcSystem.getUsername(), pcSystem.getPassword()};
Process proc = new ProcessBuilder(cmdCommand).start();

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.