VBScript+SCR+NetApi+Accoreconsole 批处理dwg文件
继上次powershell运行accoreconsole(https://www.cnblogs.com/NanShengBlogs/p/10981687.html)的研究之后又觉得不是很合适,毕竟powershell还存在权限问题,不像vbs这么windows原生的的脚本好用。
脚本主要部分

1 Option Explicit 2 3 Dim acoreFn,fso 4 5 acoreFn=inputbox("输入AutoCAD的版本号","用户输入","2019") 6 7 if int(acoreFn)>=2013 then 8 9 Set fso = CreateObject("Scripting.FileSystemObject") 10 11 if fso.FileExists("C:\Program Files\Autodesk\AutoCAD " & acoreFn & "\accoreconsole.exe") then 12 13 acoreFn=chr(34) & "C:\Program Files\Autodesk\AutoCAD " & acoreFn & "\accoreconsole.exe" &chr(34) 14 15 call AccoreCmdExecute("myScrFile.scr",acoreFn) 16 else 17 18 msgbox "请确认本机的autocad"& int(acoreFn) & "安装路径为:" & vbNewLine & "C:\Program Files\Autodesk\AutoCAD " & acoreFn & "",vbError+vbOKOnly 19 20 end if 21 22 else 23 msgbox "Accoreconsole.exe 程序从AutoCAD2013 开始支持!",vbError+vbOKOnly 24 25 end if 26 27 set fso=nothing 28 29 public sub AccoreCmdExecute(scrFileName,accoreconsoleFileName) 30 31 Dim objFSO,curFdName,fl,fd,WshShell,scrFile,args 32 33 Set objFSO = CreateObject("Scripting.FileSystemObject") 34 35 curFdName = objFSO.GetFile(WScript.ScriptFullName).ParentFolder 36 37 scrFile=" /s " & chr(34) & curFdName & "\" & scrFileName & chr(34) 38 39 set fd=objFSO.GetFolder(curFdName) 40 41 42 Set WshShell=Wscript.CreateObject("Wscript.Shell") 43 44 for each fl in fd.Files 45 46 if LCase(objFSO.GetExtensionName(fl))="dwg" then 47 48 if (objFSO.getfile(fl).Attributes and 1) or CheckFileInuse(fl)=true then 49 50 msgbox fl.name & "是只读文件或者被打开,无法执行脚本命!" 51 else 52 args=" /i " & chr(34) & curFdName& "\" & fl.name & chr(34) 53 54 WshShell.run accoreconsoleFileName & args & scrFile,0,false 55 56 msgbox fl.name & "执行完成!" 57 58 end if 59 60 end if 61 next 62 63 set fd=nothing 64 set objFSO=nothing 65 set WshShell=nothing 66 67 end sub 68 69 public function CheckFileInuse(fn) 70 71 dim fso,fl 72 73 Set fso = CreateObject("Scripting.FileSystemObject") 74 75 Set fl = fso.GetFile(fn) 76 77 ON ERROR RESUME NEXT 78 79 fl.move fl.path 80 81 if Err=70 then 82 83 CheckFileInuse=true 84 else 85 CheckFileInuse=false 86 end if 87 88 Set fso =nothing 89 90 Set fl = nothing 91 92 end function
执行命令的部分
检查文件名是否被打开。
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· winform 绘制太阳,地球,月球 运作规律
· 超详细:普通电脑也行Windows部署deepseek R1训练数据并当服务器共享给他人
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· AI 智能体引爆开源社区「GitHub 热点速览」
· 写一个简单的SQL生成工具