-
- ‘网络驱动器映射(测试服务器)
- sRemoteAdress = “192.168.1.202″ ‘远程驱动器所在IP地址
- sUser=”qqqiu” ‘远程驱动器访问用户名
- sPwd=”124!@#” ‘远程驱动器访问密码
- ‘自定义被映射盘符
- sDrive1=”x:”
- sDrive2=”y:”
- sDrive3=”z:”
- AppPath=left(Wscript.ScriptFullName,len(Wscript.ScriptFullName)-len(Wscript.ScriptName)) ‘获取但其脚本运行目录
- Set SF = CreateObject(”Scripting.FileSystemobject”)
- Set WS = CreateObject(”Wscript.Shell”)
- Set WN = CreateObject(”WScript.Network”)
- Set SA = CreateObject(”Shell.Application”)
- If SF.DriveExists(sDrive1 & “\”) = True Then WN.RemoveNetworkDrive sDrive1 ’通过FSO函数判断本地是否存在同盘符驱动器,若存在,则通过WMI函数断开该驱动器
- WN.MapNetworkDrive sDrive1,”\\” & sRemoteAdress & “\web”,1,sUser,sPwd ’通过通过WMI函数映射远程驱动器
- SA.NameSpace(sDrive1).Self.Name = “测试服务器”
- If SF.DriveExists(sDrive2 & “\”) = True Then WN.RemoveNetworkDrive sDrive2
- WN.MapNetworkDrive sDrive2, “\\” & sRemoteAdress & “\” & sUser,1,sUser,sPwd
- SA.NameSpace(sDrive2).Self.Name = “我的备份盘”
- If SF.DriveExists(sDrive3 & “\”) = True Then WN.RemoveNetworkDrive sDrive3
- WN.MapNetworkDrive sDrive3,”\\” & sRemoteAdress & “\commonshare”,1
- SA.NameSpace(sDrive3).Self.Name = “公用共享盘”
- WS.Regwrite “HKLM\Software\Microsoft\Windows\CurrentVersion\Run\MyNetShare”,Wscript.ScriptFullName ‘将VBS脚本自身添加到开机启动项中,方便开机自动映射远程驱动器
复制代码
MapNetworkDrive 方法说明将共享网络驱动器添加到计算机系统中。