Results 1 to 3 of 3
- 12-29-2011, 09:31 PM #1
Member
- Join Date
- Dec 2011
- Posts
- 2
- Rep Power
- 0
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
- 12-29-2011, 09:43 PM #2
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?
- 12-30-2011, 03:18 AM #3
Member
- Join Date
- Dec 2011
- Posts
- 2
- Rep Power
- 0
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
-
Question About Shared Objects
By mattloto in forum New To JavaReplies: 1Last Post: 02-08-2011, 02:43 AM -
Disconnect a telnet session
By icon in forum NetworkingReplies: 0Last Post: 10-02-2010, 11:00 PM -
Best way to format a drive/thumb drive in java...
By vandyke in forum Advanced JavaReplies: 1Last Post: 12-09-2009, 01:32 AM -
Scannig for shared files
By Falcon_minsk in forum NetworkingReplies: 0Last Post: 11-07-2009, 11:29 AM -
how can i disconnect client?
By dim_ath in forum New To JavaReplies: 1Last Post: 01-24-2008, 04:52 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks