映射网络驱动器VBS脚本
On error resume next
strRemotePath = "\\UNC路径"
strNewName = "要显示的名称"
Set objNetwork = CreateObject("Wscript.Network")
Set colDrives = objNetwork.EnumNetworkDrives
For i = 0 to colDrives.Count-1 Step 2
Set objShell = CreateObject("Shell.Application")
strDriveLetter = colDrives.Item(i)
strName = objShell.NameSpace(strDriveLetter).Self.Name
strName = Left(strName,Len(strName)-5)
If strName = strNewName Then WScript.Quit
strDriveLetter = Chr(Asc(Left(colDrives.Item(i),1))-1) & ":"
Next
If strDriveLetter= "" Then strDriveLetter="Z:"
' Section to map the network drive
Set objNetwork = CreateObject("WScript.Network")
objNetwork.MapNetworkDrive strDriveLetter, strRemotePath
' Section which actually (re)names the Mapped Drive
Set objShell = CreateObject("Shell.Application")
objShell.NameSpace(strDriveLetter).Self.Name = strNewName
strRemotePath = "\\UNC路径"
strNewName = "要显示的名称"
Set objNetwork = CreateObject("Wscript.Network")
Set colDrives = objNetwork.EnumNetworkDrives
For i = 0 to colDrives.Count-1 Step 2
Set objShell = CreateObject("Shell.Application")
strDriveLetter = colDrives.Item(i)
strName = objShell.NameSpace(strDriveLetter).Self.Name
strName = Left(strName,Len(strName)-5)
If strName = strNewName Then WScript.Quit
strDriveLetter = Chr(Asc(Left(colDrives.Item(i),1))-1) & ":"
Next
If strDriveLetter= "" Then strDriveLetter="Z:"
' Section to map the network drive
Set objNetwork = CreateObject("WScript.Network")
objNetwork.MapNetworkDrive strDriveLetter, strRemotePath
' Section which actually (re)names the Mapped Drive
Set objShell = CreateObject("Shell.Application")
objShell.NameSpace(strDriveLetter).Self.Name = strNewName