我正在尝试创建一个脚本来删除漫游用户的映射网络驱动器 即如果映射与其当前子网不同 例如:如果用户位于子网10.10.50上,并且已映射网络驱动器 10.10.40,映射将被删除(但它必须是通用脚本,因为我的公司有近50个分支/子网。 我的问题是从枚举映射驱动器获取IP地址(它使用的是enumarting到一个数组 然后通过vbscript中的拆分操作将其拆分
Option Explicit
Dim objNetwork, colDrives, i, DriveLetter, DrivePath
Set objNetwork = CreateObject("Wscript.Network")
Set colDrives = objNetwork.EnumNetworkDrives
' extra section to troubleshoot
If colDrives.Count= 0 Then
WScript.Echo "Guy's Warning: No Drive Mapped "
WScript.Quit(0)
End If
' here is where the script reads the Array
Dim DriveServer
For i = 0 To colDrives.Count -1 Step 2 ' this check the drive letter list
DriveLetter = colDrives.item(i) ' this follows drive letter
DrivePath = colDrives.Item(i+1)
If Len(DriveLetter) > 0 Then
DriveServer = getServerFromPath(DrivePath)
If Not Ping(DriveServer) Then
objNetwork.RemoveNetworkDrive DriveLetter, True, True
End If
End If
Next
答案 0 :(得分:0)
您可以从路径\\10.10.50.23\share
中提取服务器名称或IP地址,如下所示:
Function GetServerFromPath(p)
GetServerFromPath = Split(Mid(p, 3), "\")(0)
End Function
WScript.Echo GetServerFromPath("\\10.10.50.23\share")