Results 1 to 3 of 3
  1. #1
    EricHamel is offline Member
    Join Date
    Dec 2011
    Posts
    2
    Rep Power
    0

    Default Cannot disconnect a shared drive with Runtime

    Hi:

    I need to disconnect a network share on Windows before I reconnect that drive to another share. Somehow, the disconnect doesn't work. The code:

    Runtime rt = Runtime.getRuntime();
    try {
    rt.exec(new String("net use t: /delete"));
    } catch (Exception e) {
    System.out.println("Failed: " + e.getMessage());
    }

    I don't get a failed message, but the drive does not get disconnected. When I run that command in a command window (net use t: /delete), the command executes just fine.

    As further info, if I don't have anything connected to t:, the subsequent connection command:

    rt.exec(new String("net use t: " + newSharePath + " /persistent:yes"));

    works just fine. It will not work, however, if something is still connected to t:.

    Any hints would be appreciated as to why the disconnect doesn't work from Java using Runtime.

    Regards,

    Éric

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,274
    Rep Power
    25

    Default Re: Cannot disconnect a shared drive with Runtime

    Have you looked at the streams for the Process to see if there are any error messages there?

  3. #3
    EricHamel is offline Member
    Join Date
    Dec 2011
    Posts
    2
    Rep Power
    0

    Default Re: Cannot disconnect a shared drive with Runtime

    Well, more research yielded the following:

    net use will (silently!) not disconnect a drive if that drive is active somehow (like if you have it selected in Windows Explorer). And there is not an option to force disconnect, as there is with Windows Scripting Host.

    So I guess I'll have to look into learning to use WSH through com4j.

    Éric

Similar Threads

  1. Question About Shared Objects
    By mattloto in forum New To Java
    Replies: 1
    Last Post: 02-08-2011, 02:43 AM
  2. Disconnect a telnet session
    By icon in forum Networking
    Replies: 0
    Last Post: 10-02-2010, 11:00 PM
  3. Best way to format a drive/thumb drive in java...
    By vandyke in forum Advanced Java
    Replies: 1
    Last Post: 12-09-2009, 01:32 AM
  4. Scannig for shared files
    By Falcon_minsk in forum Networking
    Replies: 0
    Last Post: 11-07-2009, 11:29 AM
  5. how can i disconnect client?
    By dim_ath in forum New To Java
    Replies: 1
    Last Post: 01-24-2008, 04:52 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •