公司的电脑每次离职都要清理共享网盘,故写了一段脚本,一键清除. 步骤如下:

  1. 开始菜单里面打开文件编辑器
  2. 把下面的代码复制粘贴到了txt文本里面.
    ' 清除映射的网盘及保存的密码
    Option Explicit
    ' 指定要清除的服务器IP或名称
    Dim serverList
    serverList = Array("192.168.1.100", "server1", "server2") ' 替换为目标服务器的名称或IP地址
    ' Function to delete network shares from the specifiend servers
    Sub DeleteNetworkShares()
        Dim objNetwork, colShares, serverName, i, j
        Set objNetwork = CreateObject("WScript.Network")
        Set colShares = objNetwork.EnumNetworkDrives()
        For i = 0 To UBound(serverList)
            serverName = serverList(i)
            For j = 0 To colShares.Count - 1 Step 2
                ' colShares(j) is the drive letter, colShares(j + 1) is the network path
                If InStr(1, colShares(j + 1), "\\" & serverName, vbTextCompare) > 0 Then
                    objNetwork.RemoveNetworkDrive colShares(j), True, True
                End If
            Next
        Next
        Set colShares = Nothing
        Set objNetwork = Nothing
    End Sub
    ' Function to clear saved credentials for the specified servers
    Sub ClearSavedCredentials()
        Dim objShell, objExec, serverName, i, strCommand
        Set objShell = CreateObject("WScript.Shell")
        
        For i = 0 To UBound(serverList)
            serverName = serverList(i)
            ' Command to delete saved credentials for the specified server
            strCommand = "cmdkey /delete:" & serverName
            objShell.Run strCommand, 0, True
        Next
        Set objShell = Nothing
    End Sub
    ' Main script execution
    DeleteNetworkShares()
    ClearSavedCredentials()
    WScript.Echo "保存的密码己清除,共享网盘己断开!"
    
  3. 保存为一键清除.vbs脚本

运行集存的vbs脚本.