找回密码
 加入
搜索
查看: 3979|回复: 3

如何实现类似于 net use * /delete /y 的功能?

[复制链接]
发表于 2009-4-12 19:18:56 | 显示全部楼层 |阅读模式
如题。
在UDF的NetShare Management里绕晕了。
我的设想是搜索所有网络连接,然后删除。但是找不到可用的函数。

[ 本帖最后由 sensel 于 2009-4-12 23:15 编辑 ]
发表于 2009-4-12 21:00:23 | 显示全部楼层

$aResult = _NetUseEnum()
For $o = 0 to @Extended - 1
        _NetUseDel($aResult[$o][0])
        _NetUseDel($aResult[$o][1])
Next

Func _NetUseDel($sUseName, $sServer = "")
        Local $iResult

        $iResult = DllCall("netapi32.dll", "int", "NetUseDel", _
                        "wstr", $sServer, _
                        "wstr", $sUseName, _
                        "dword", 2)
        Return SetError($iResult[0], 0, $iResult[0] = 0)
EndFunc        ;==>_NetUseDel()


Func _NetUseEnum($sServer = "")
        Local $iResult, $iCount, $pUse, $tUse, $tLocal, $tRemote, $aResult[1][2]
        $iResult = DllCall("netapi32.dll", "int", "NetUseEnum", _
                        "wstr", "", _
                        "dword", 0, _
                        "dword*", 0, _
                        "dword", -1, _
                        "dword*", 0, _
                        "dword*", 0, _
                        "dword*", 0)
        $iCount = $iResult[6]
        $pUse = $iResult[3]
        If $iCount = 0 Then Return SetError($iResult[0], 0, False)
        Redim $aResult[$iCount][2]

        For $o = 1 to $iCount
                $tUse = DllStructCreate("ptr;ptr", $pUse)
                $tLocal = DllStructCreate("wchar[256]", DllStructGetData($tUse, 1))
                $tRemote = DllStructCreate("wchar[256]", DllStructGetData($tUse,2))
                $aResult[$o - 1][0] = DllStructGetData($tLocal, 1)
                $aResult[$o - 1][1] = DllStructGetData($tRemote, 1)

                $tLocal = 0
                $tRemote = 0
                $pUse += DllStructGetSize($tUse)
        Next
        $tUse = 0
        Return SetError($iResult[0], $iCount, $aResult)
EndFunc        ;==>_NetUseEnum()
 楼主| 发表于 2009-4-12 23:14:38 | 显示全部楼层

回复 2# pusofalse 的帖子

虚拟机测试通过。谢谢!

发现一个小问题是NetUseDel似乎只删除信任关系,对于已经映射的网络盘符无法删除。还好au3已经提供了DriveMapDel,只要判断$aResult[$o][0]是否为空再决定调用哪个就可以了。
发表于 2014-4-9 19:38:45 | 显示全部楼层
學習啦!~感謝您!~
您需要登录后才可以回帖 登录 | 加入

本版积分规则

QQ|手机版|小黑屋|AUTOIT CN ( 鲁ICP备19019924号-1 )谷歌 百度

GMT+8, 2024-9-28 11:25 , Processed in 0.100061 second(s), 20 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表