我有一个简单的登录脚本,用于为用户映射驱动器
On Error Resume Next
Set objNetwork = CreateObject("Wscript.Network")
Set colDrives = objNetwork.EnumNetworkDrives
For i = 0 to colDrives.Count-1 Step 2
objNetwork.RemoveNetworkDrive colDrives.Item(i)
Next
Dim Network
Set Network = CreateObject("Wscript.network")
Network.MapNetworkDrive "P:","\\server-A\share name A"
Network.MapNetworkDrive "N:","\\server-A\share name B"
Network.MapNetworkDrive "S:","\\server-A\share name C"
Network.MapNetworkDrive "L:","\\server-B\share name A"
Network.MapNetworkDrive "T:","\\server-C\share name"
Network.MapNetworkDrive "V:","\\server-B\share name B"
Network.MapNetworkDrive "W:","\\server-D\share name"
我想把
"\\server-A\share name A"
"\\server-A\share name B"
"\\server-A\share name C"
"\\server-B\share name A"
"\\server-C\share name"
"\\server-B\share name B"
"\\server-D\share name"
在文本文件中,让我的脚本读取并将其插入脚本中。任何人都可以帮忙解决这个问题吗?
答案 0 :(得分:1)
考虑以下代码:
On Error Resume Next
Const SharesFile = "C:\Test\shares.txt"
Set objNetwork = CreateObject("WScript.Network")
Set colDrives = objNetwork.EnumNetworkDrives
For i = 0 to colDrives.Count -1 Step 2
objNetwork.RemoveNetworkDrive colDrives.Item(i)
Next
Set objTxtStream = CreateObject("Scripting.FileSystemObject").OpenTextFile(SharesFile, 1, False, -2) ' charset: -2 = System default, -1 = Unicode, 0 = ASCII
For Each strLetter In Array("P:", "N:", "S:", "L:", "T:", "V:", "W:")
If objTxtStream.AtEndOfStream Then Exit For
objNetwork.MapNetworkDrive strLetter, objTxtStream.ReadLine
Next
shares.txt
文本文件内容应该没有引号:
\\server-A\share name A
\\server-A\share name B
\\server-A\share name C
\\server-B\share name A
\\server-C\share name
\\server-B\share name B
\\server-D\share name