我需要使用VBScript將網絡驅動器映射到網絡路徑。網絡路徑直接從輸入讀取。我應該如何映射網絡驅動器以及如何檢查輸入的網絡路徑是否已經存在?在VBScript中映射網絡驅動器並檢查其是否存在
2
A
回答
3
在您運行以下命令VBScript文件:
net use [NetDrive:] [Network Path]
例如:
net use Z: \\Hadi\temp
示例命令將映射\哈迪\ TEMP到Z:
而且看看在this VBScript文件映射網絡驅動器。
5
我創建了一個子程序映射驅動器...
MapDrive "H:","\\server\share"
Sub MapDrive(letter, uncpath)
on error Resume Next
dim drivetype, currentmapping
dim objWMIService
dim colDisks, objDisk
'Set wshnetwork = CreateObject("Wscript.Network")
Set objWMIService = GetObject("winmgmts:" & _
"{impersonationLevel=impersonate}!\\.\root\cimv2")
Set colDisks = objWMIService.ExecQuery _
("Select * from Win32_LogicalDisk Where Name = """ & letter & """")
For Each objDisk In colDisks
drivetype = objDisk.DriveType
currentmapping = objDisk.ProviderName
Next
if (drivetype <> 4 and drivetype <> 0) then
NotifyUser ucase(letter) & " cannot be mapped due to a physical device already reserving that drive letter" & vbcrlf & _
"This is most frequently caused by a thumbdrive or external disk.",5
exit Function
end if
if (ucase(currentmapping) = ucase(uncpath)) then
exit function
end If
if (drivemappings.Exists(uncpath)) then
drivemappings.Add uncpath & "(" & letter & ")", letter
else
drivemappings.Add uncpath, letter
end if
if (currentmapping <> "") then
wshnetwork.RemoveNetworkDrive letter,,True
end if
wshnetwork.MapNetworkDrive letter, uncpath, true
on Error goto 0
End Sub
我把它留給你做處理錯誤檢查等。另外,如果你喜歡的網絡使用路線,你可以不喜歡..
dim wshShell
Set wshShell = CreateObject("WScript.Shell")
wshshell.run "cmd /c net use H: ""\\server\share""",1,True
您可以進一步自動使用下一個可用的驅動器號來映射驅動器,例如使用創建的The Scripting Guys示例。
Set objDictionary = CreateObject("Scripting.Dictionary")
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colDisks = objWMIService.ExecQuery("Select * from Win32_LogicalDisk")
For Each objDisk in colDisks
objDictionary.Add objDisk.DeviceID, objDisk.DeviceID
Next
For i = 67 to 90
strDrive = Chr(i) & ":"
If objDictionary.Exists(strDrive) Then
Else
Wscript.Echo strDrive & " is the next available drive letter."
Wscript.Quit
End If
Next
Wscript.Echo "There are no available drive letters on this computer.」
我希望這是有幫助的。
相關問題
- 1. vb.net如何檢查網絡驅動器是否持久映射
- 2. 如何檢查映射網絡驅動器是否存在主機名C#
- 3. 如何自動映射網絡驅動器,並檢查驅動器號是否正在使用
- 4. 映射網絡驅動器
- 5. 映射網絡驅動器
- 6. 映射網絡驅動器
- 7. 檢查共享網絡驅動器中是否存在文件
- 8. 查詢映射網絡驅動器
- 9. 檢查網絡驅動器上是否存在目錄
- 10. Powershell:檢查網絡驅動器是否存在,如果沒有,映射它,然後仔細檢查
- 11. 檢查驅動器是否映射並激活
- 12. 檢測路徑是否在Windows映射的網絡驅動器上
- 13. php XAMPP作爲服務網絡映射驅動器檢查
- 14. VBScript中如何檢查什麼驅動器映射到
- 15. 映射網絡驅動器上的FileSystemWatcher
- 16. 映射網絡驅動器與陣列
- 17. Powershell /批量網絡映射驅動器
- 18. 檢查是否存在windows驅動器
- 19. 如何在C#中獲得網絡映射驅動器VolumeLabel?
- 20. 如何在Python中刷新網絡驅動器映射
- 21. 在Windows 7中映射網絡驅動器
- 22. 在Visual Basic 2010中映射網絡驅動器
- 23. 檢測文件是否在python中的網絡驅動器上
- 24. 檢查文件是否是共享網絡驅動器上accessable
- 25. 映射網絡驅動器檢查.txt文件中的用戶列表
- 26. VBA,搜索網絡驅動器中是否存在文件名
- 27. 僅在連接到域時映射網絡驅動器
- 28. 如何在批次內映射網絡驅動器
- 29. 映射網絡驅動器C#編程在Windows 10
- 30. 映射網絡驅動器在WiFi上執行緩慢