映射网络驱动器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
posted @ 2009-10-21 16:21  与时俱进  阅读(2727)  评论(0编辑  收藏  举报
友情链接:同里老宅院民居客栈