tengte 发表于 2009-6-30 19:18:00

[求助]关于通过注册表自动加载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\&lt;&lt;Unnamed Profile&gt;&gt;\Dialogs\Appload\Startup子键下的1Startup和NumStartup写入了相应的内容。(其作用与在启动组中加入相同,但我为了能方便别人使用,故用程序写入)</p><p>但打开AutoCAD2007后,没有按预期的那样自动加载指定的FAS文件,反复多次依然无果。直到我在CAD命令行输入AP(即手动加载应用程序的命令)后,即使不用任何操作就退出该命令,再打开另一DWG文件,奇迹发生了,FAS文件被加载了。以后每次打开CAD时FAS文件都能被正常的加载了。这是为什么呢?</p><p>有没有高手能解释一下呢?</p>

liminnet 发表于 2009-7-3 15:02:00

tengte 发表于 2009-7-4 03:46:00

<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\&lt;&lt;Unnamed Profile&gt;&gt;\Dialogs\Appload\Startup<br/>Boot = "HKCU\"<br/>Key = "Software\Autodesk\AutoCAD\"<br/>Value = WshShell.RegRead(Boot &amp; Key &amp; "CurVer")<br/>Key = Key &amp; Value &amp; "\"<br/>Value = WshShell.RegRead(Boot &amp; Key &amp; "CurVer")<br/>Key = Key &amp; Value &amp; "\"<br/>SubKey = "Profiles\"<br/>Value = WshShell.RegRead(Boot &amp; Key &amp; SubKey)<br/>SubKey = SubKey &amp; Value &amp; "\Dialogs\Appload\Startup\"<br/>Value = WshShell.RegRead(Boot &amp; Key &amp; SubKey)<br/>IF Value&lt;&gt;"" Then<br/>&nbsp; Set REG = GetObject("winmgmts:\\.\root\default:StdRegProv")<br/>&nbsp; Item = Value &amp; "Startup"<br/>&nbsp; REG.GetStringValue &amp;H80000001, Key &amp; SubKey, Item, Value<br/>&nbsp; If IsNull(Value) Then<br/>&nbsp;&nbsp;&nbsp; Value = ""<br/>&nbsp; Else<br/>&nbsp;&nbsp;&nbsp; Value = WshShell.RegRead(Boot &amp; Key &amp; SubKey &amp; Item)<br/>&nbsp;&nbsp;&nbsp; If UCase(Right(Value,9))&lt;&gt;"\LOAD.FAS" Then Value = ""<br/>&nbsp; End If <br/>End IF<br/>IF Value&lt;&gt;"" Then<br/>&nbsp; MsgBox "TB Tools 已在自动加载列表中!"<br/>Else<br/>&nbsp; Path = WshShell.CurrentDirectory &amp; "\Load.fas"<br/>&nbsp; Value = WshShell.RegRead(Boot &amp; Key &amp; SubKey &amp; "NumStartup")<br/>&nbsp; Value = CStr(CInt(Value)+1)<br/>&nbsp; WshShell.RegWrite Boot &amp; Key &amp; SubKey, Value, "REG_SZ"<br/>&nbsp; WshShell.RegWrite Boot &amp; Key &amp; SubKey &amp; "NumStartup", Value, "REG_SZ"<br/>&nbsp; WshShell.RegWrite Boot &amp; Key &amp; SubKey &amp; Value &amp; "Startup", Path, "REG_SZ"<br/>&nbsp; 'HKEY_CURRENT_USER\Software\Autodesk\AutoCAD\R17.0\ACAD-5001:409\Applications\AcadAppload<br/>&nbsp; Path = Boot &amp; Key &amp; "Applications\AcadAppload\LOADCTRLS"<br/>&nbsp; Value = WshShell.RegRead(Path)<br/>&nbsp; Value = Value or 2<br/>&nbsp; WshShell.RegWrite Path, Value, "REG_DWORD"<br/>&nbsp; MsgBox "成功加入自动加载列表!"<br/>End IF<br/></p>

xshrimp 发表于 2009-6-30 20:36:00

<p>为了保证你的程序能加载,还需要通知AutoCAD启动时加载Appload模块。</p><p>在安装程序中读取注册表 'HKEY_LOCAL_MACHINE\\.....\\Autodesk\\....\\Applications\\AcadAppload'</p><p>&nbsp;'LOADCTRLS'这个值</p><p>将其与十进制数字2(二进制为10)作“OR”运算。然后写回,覆盖之。</p><p>这样可以保证AutoCAD启动时会加载Appload.arx模块。</p>

tengte 发表于 2009-6-30 20:53:00

<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>

tengte 发表于 2009-7-2 21:59:00

问题解决了,还是用的<font face="Verdana" color="#61b713"><strong>xshrimp的方法。不过不是</strong><font color="#000000">'HKEY_LOCAL_MACHINE,而是HKEY_CURRENT_USER。</font></font>

xshrimp 发表于 2009-7-4 15:49:00

我来个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
)

clh521 发表于 2009-7-4 19:43:00

<p>呵呵,不错呀我正想编这个程序,正好被我找到了,不用编了,谢谢分享</p>

liminnet 发表于 2009-7-5 17:28:00

liminnet 发表于 2009-7-6 08:55:00

页: [1] 2 3 4
查看完整版本: [求助]关于通过注册表自动加载FAS文件的 奇怪问题(已解决)