【发布时间】:2021-02-23 05:05:49
【问题描述】:
我需要创建一个 bat 文件来检查驱动器号的可用性并将共享文件夹映射到空闲驱动器号上。
我尝试在 IF 条件下工作,但如果用户多次启动它,这很容易出现多个驱动器映射。
任何人都可以帮助了解如何为此使用 FOR 循环吗?
if not exist U:\ (
net use U: \\test\branchshare$
exit
)
elseif not exist X:\ (
net use X: \\test\branchshare$
exit
)
elseif not exist Y:\ (
net use Y: \\test\branchshare$
exit
)
pause
【问题讨论】:
-
net use * \\test\branchshare$获取第一个空闲驱动器号。测试是否已经连接,可以使用net use | find /i "\\test\branchshare$" && echo already connected
标签: windows batch-file cmd command-line command