在 Windows 7 中断开共享时如何避免 12 秒延迟? [英] How to avoid 12 seconds delay when disonnecting from share in Windows 7?

查看:36
本文介绍了在 Windows 7 中断开共享时如何避免 12 秒延迟?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在制作一些使用 NetUseAdd 和 NetUseDel 函数来连接/断开连接以共享的实用程序.在 Windows 7 中,我注意到在调用 NetUseDel 和真正断开连接之间经过了将近 12 秒.我做了一些调查,发现 net use \server/del 也在 12 秒后断开连接.这是小脚本和 Wireshark 输出,对应于脚本的运行:

I'm making some utils that uses NetUseAdd and NetUseDel functions to connect/disconnect to share. In Windows 7 I noticed that between calling NetUseDel and real disconnnection passes nearly 12 seconds. I made some investigations and found that net use \server /del also disonnects only after 12 seconds. Here's little script and Wireshark output, corresponding to run of script:

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

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

以最后一条 tree connect smb 命令为参考,我们可以看到,tree disconnect 延迟了 12 秒.

Setting last tree connect smb command as reference, we can see, that tree disconnect delayed for 12 seconds.

有谁知道如何缩短这样的超时时间?

Does anyone know how to cut such a timeout?

推荐答案

连接有时可以保持活动状态甚至超过 12 秒.诀窍是在删除后强制进行错误登录.

The connection can stay alive sometimes even more than 12 seconds. The trick is to force a bad login after deletion.

如果您强制进行错误登录,则共享将立即无法访问.为此,我们可以使用本地来宾帐户(它通常会给出错误登录失败:帐户当前已禁用."并且即使启用它也无法访问).

If you force a bad login then the share will be inaccessible immediately. We can use the local Guest account for that (it will usually give the error "Logon failure: account currently disabled." and even if it is enabled it will not have access).

而不仅仅是:

net use \\server /delete

我们将执行:

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

执行第三行以防访客登录成功(它使用 2>nul 将错误流重定向到 nul 设备,以避免显示任何错误消息).

The third line is executed just in case the Guest login succedes (it usses 2>nul for error stream redirection to the nul device, to avoid displaying any error messages).

这是使用net use"的批处理版本命令,但在使用 netapi32.dll 中的 NetUseAdd 和 NetUseDel 或 mpr.dll 中的 WNetAddConnection 和 WNetCancelConnection 时,可以应用相同的解决方案.

This is the batch version that uses 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.

这篇关于在 Windows 7 中断开共享时如何避免 12 秒延迟?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆