How to avoid a 12 second delay when disconnecting from sharing in Windows 7?

I am making some utilities that use the NetUseAdd and NetUseDel functions to connect / disconnect for sharing. In Windows 7, I noticed that almost 12 seconds elapse between the call to NetUseDel and the actual disconnect. I did some research and found that net use \ server / del also shuts down after only 12 seconds. Here is a small script and Wireshark output corresponding to the run of the script:

net use \\server "" /user:"" net use \\server /delete 

http://i.stack.imgur.com/5CyCw.png

Installing the last tree connects the smb command as a link, we can see that the tree disconnection is disabled for 12 seconds.

Does anyone know how to shorten such a timeout?

+4
source share
3 answers

Why would you delay the shutdown? The whole point of the timeout is to essentially cache the shared resource, since Windows knows that if you get access to the resource once, you will most likely do it again. He does not want to waste time constantly configuring and breaking the connection, which can easily be left open, so it delays its closure.

If you need to access a resource, this will help you. Do not worry about deleting it so you can recreate it; just use it.

0
source

Since the SMB client kernel driver handles these requests, you cannot control when it really shuts down, the 12 second delay that you experience is actually just the time that the kernel handler took to kill the underlying tcp connection. as a workaround, I would use NetUseEnum to make sure that the connection was actually deleted in the while loop using a counter.

you can see my answer here for more information on how to create multiple connections besides using a different smb implementation or creating a Windows workstation on one connection from which you are good luck.

0
source

Communication can remain alive sometimes even more than 12 seconds. The trick is to block a failed login after deletion.

If you block bad entry, this resource will be unavailable immediately. To do this, we can use a local guest account (usually it gives the error "Login failed: account is currently disabled." And even if it is turned on, it will not have access).

Instead simply:

 net use \\server /delete 

We will do:

 net use \\server /delete net use \\server "" /user:"Guest" net use \\server /delete 2>nul 

The third line is executed only if the guest input is succedes (it uses 2> nul to redirect the error stream to the nul device to avoid displaying error messages).

This is a batch version using the "net use" command, but the same solution can be applied when using NetUseAdd and NetUseDel from netapi32.dll or WNetAddConnection and WNetCancelConnection from mpr.dll.

0
source

All Articles