[求助]关于通过注册表自动加载FAS文件的 奇怪问题(已解决)
本帖最后由 作者 于 2009-7-6 23:16:41 编辑 <br /><br /> <p>我写了一些LISP程序,并编译为FAS文件,想在CAD启动时自动加载我的程序,于是在用VBS程序在注册表中HKEY_CURRENT_USER\Software\Autodesk\AutoCAD\R17.0\ACAD-5001:409\Profiles\<<Unnamed Profile>>\Dialogs\Appload\Startup子键下的1Startup和NumStartup写入了相应的内容。(其作用与在启动组中加入相同,但我为了能方便别人使用,故用程序写入)</p><p>但打开AutoCAD2007后,没有按预期的那样自动加载指定的FAS文件,反复多次依然无果。直到我在CAD命令行输入AP(即手动加载应用程序的命令)后,即使不用任何操作就退出该命令,再打开另一DWG文件,奇迹发生了,FAS文件被加载了。以后每次打开CAD时FAS文件都能被正常的加载了。这是为什么呢?</p><p>有没有高手能解释一下呢?</p> <p>没问题!我用的VBS文件,指定加载同目录下的Load.fas文件,全部代码如下:</p><p>Dim WshShell, REG, Path, Key, SubKey, Value<br/>Set WshShell = WScript.CreateObject("WScript.Shell")<br/>'HKEY_CURRENT_USER\Software\Autodesk\AutoCAD\R17.0\ACAD-5001:409\Profiles\<<Unnamed Profile>>\Dialogs\Appload\Startup<br/>Boot = "HKCU\"<br/>Key = "Software\Autodesk\AutoCAD\"<br/>Value = WshShell.RegRead(Boot & Key & "CurVer")<br/>Key = Key & Value & "\"<br/>Value = WshShell.RegRead(Boot & Key & "CurVer")<br/>Key = Key & Value & "\"<br/>SubKey = "Profiles\"<br/>Value = WshShell.RegRead(Boot & Key & SubKey)<br/>SubKey = SubKey & Value & "\Dialogs\Appload\Startup\"<br/>Value = WshShell.RegRead(Boot & Key & SubKey)<br/>IF Value<>"" Then<br/> Set REG = GetObject("winmgmts:\\.\root\default:StdRegProv")<br/> Item = Value & "Startup"<br/> REG.GetStringValue &H80000001, Key & SubKey, Item, Value<br/> If IsNull(Value) Then<br/> Value = ""<br/> Else<br/> Value = WshShell.RegRead(Boot & Key & SubKey & Item)<br/> If UCase(Right(Value,9))<>"\LOAD.FAS" Then Value = ""<br/> End If <br/>End IF<br/>IF Value<>"" Then<br/> MsgBox "TB Tools 已在自动加载列表中!"<br/>Else<br/> Path = WshShell.CurrentDirectory & "\Load.fas"<br/> Value = WshShell.RegRead(Boot & Key & SubKey & "NumStartup")<br/> Value = CStr(CInt(Value)+1)<br/> WshShell.RegWrite Boot & Key & SubKey, Value, "REG_SZ"<br/> WshShell.RegWrite Boot & Key & SubKey & "NumStartup", Value, "REG_SZ"<br/> WshShell.RegWrite Boot & Key & SubKey & Value & "Startup", Path, "REG_SZ"<br/> 'HKEY_CURRENT_USER\Software\Autodesk\AutoCAD\R17.0\ACAD-5001:409\Applications\AcadAppload<br/> Path = Boot & Key & "Applications\AcadAppload\LOADCTRLS"<br/> Value = WshShell.RegRead(Path)<br/> Value = Value or 2<br/> WshShell.RegWrite Path, Value, "REG_DWORD"<br/> MsgBox "成功加入自动加载列表!"<br/>End IF<br/></p> <p>为了保证你的程序能加载,还需要通知AutoCAD启动时加载Appload模块。</p><p>在安装程序中读取注册表 'HKEY_LOCAL_MACHINE\\.....\\Autodesk\\....\\Applications\\AcadAppload'</p><p> 'LOADCTRLS'这个值</p><p>将其与十进制数字2(二进制为10)作“OR”运算。然后写回,覆盖之。</p><p>这样可以保证AutoCAD启动时会加载Appload.arx模块。</p> <p><strong><font face="Verdana" color="#61b713">谢谢xshrimp,你的方法我试了,还是不行。</font></strong></p><p><font face="Verdana" color="#61b713"><strong>补充一点:在</strong><font color="#000000">输入AP命令后,在loaded applications列表中有我要加载的FAS文件,刷新几次后又消失了。</font></font></p> 问题解决了,还是用的<font face="Verdana" color="#61b713"><strong>xshrimp的方法。不过不是</strong><font color="#000000">'HKEY_LOCAL_MACHINE,而是HKEY_CURRENT_USER。</font></font> 我来个lsp版的。;(gps->appload-addfile "d:\\12.lsp")
(defun gps->appload-addfile (AppName / $akey $skey loadctrlnum numstartup)
(if (= (type appname) 'STR)
(progn
(setq
$skey (strcat "HKEY_CURRENT_USER\\" (vlax-product-key) "\\Profiles\\" (getvar "CPROFILE") "\\Dialogs\\Appload\\Startup")
$akey (strcat "HKEY_CURRENT_USER\\" (vlax-product-key) "\\Applications\\AcadAppload" )
)
(setq NumStartup (vl-registry-read $skey "NumStartup"))
(if NumStartup
(progn
(vl-registry-write $skey "NumStartup" (itoa (+ 1 (atoi NumStartup))))
(vl-registry-write $skey (strcat (itoa (+ 1 (atoi NumStartup))) "Startup") AppName )
)
(progn
(vl-registry-write $skey "NumStartup" "1")
(vl-registry-write $skey "1Startup" AppName )
)
)
;读取LoadCtrls的值,将这个值与2作“或”运算,再写回。这样可以保证AutoCAD启动时会加载Appload.arx模块。
(setq loadctrlnum (vl-registry-read $akey "LOADCTRLS"))
(if loadctrlnum
(vl-registry-write $akey "LOADCTRLS" (Boole 7 loadctrlnum 2))
(vl-registry-write $akey "LOADCTRLS" 15)
)
T
)
nil
);end if
) <p>呵呵,不错呀我正想编这个程序,正好被我找到了,不用编了,谢谢分享</p>