You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Batch脚本对象变量调用net use命令报System Error 67求助

问题解决方法

错误原因

System Error 67(找不到网络名)的核心原因是net use命令行的数组变量未被正确解析为实际值:你使用的%%list[%tomount%].endpoint%%套娃百分号写法,没有call前缀的情况下不会触发二次变量解析,最终传给net use命令的是原始变量名字符串,而非存储的网络路径值。
另外你的脚本还存在其他语法问题:

  • 变量定义错误:set "x = 0" 中等号两侧存在空格,实际创建的变量名是带尾部空格的x ,导致后续计数逻辑异常
  • 数组遍历逻辑冗余,最终统计的数组长度多了1,会输出不存在的数组项

修正后的完整代码

@echo off
setlocal EnableDelayedExpansion

:: 读取CSV到数组
set i=0
for /f "usebackq skip=1 tokens=1-4 delims=;" %%a in ("data.csv") do (
    set list[!i!].name=%%a
    set list[!i!].endpoint=%%b
    set list[!i!].user=%%c
    set list[!i!].pwd=%%d
    set /a i+=1
)
set /a max_idx=i-1

:: 输出可选列表
echo 可选网络驱动器列表:
for /l %%i in (0,1,%max_idx%) do (
    echo %%i: !list[%%i].name!
)

:: 接收用户选择并校验合法性
:input
set "tomount="
set /p tomount=请输入要挂载的驱动器编号:
if not defined tomount goto input
echo %tomount%| findstr /r "^[0-9]*$" >nul || (
    echo 请输入合法数字!
    goto input
)
if %tomount% lss 0 goto input
if %tomount% gtr %max_idx% (
    echo 编号超出范围!
    goto input
)

:: 挂载网络驱动器,用延迟扩展!符号直接取变量值
net use z: "!list[%tomount%].endpoint!" /user:"!list[%tomount%].user!" "!list[%tomount%].pwd!"

echo 挂载完成,按回车键卸载并退出
pause >nul
net use z: /delete /y

endlocal

关键修改说明

  • 直接使用延迟扩展语法!变量名!解析数组值,不需要用百分号套娃写法,变量解析更稳定
  • 修正了变量定义的空格问题,简化了数组长度统计逻辑
  • 增加了用户输入校验,避免非法编号导致的挂载失败
  • 给路径、账号密码加了双引号,避免路径包含空格时执行出错

内容的提问来源于stack exchange,提问作者sad

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.09.25 04:24:08