xmjiacad 发表于 2009-10-28 20:48:00

求助:VB调用CAD时,如何读注册表检测是否安装CAD?

<p>在VB程序里,调用CAD,但是不能确定别人电脑上安装了CAD,怎么判断是否安装CAD,保证程序能运行?查看资料提示读注册表信息,但还是不知道怎么下手,望各位高手赐教哈,感激不尽!!</p>

zhaoguo 发表于 2009-10-29 20:24:00

返回值

<p>1.用getobject,如果返回错误,就创建,再错误,应该就是没有安装了。</p><p>2.检查注册表是否有HKEY_LOCAL_MACHINE\SOFTWARE\Autodesk\AutoCAD\等</p><p>供参考</p>

home 发表于 2009-11-3 17:51:00

<p>可以通过vb判断是否安装了cad,并判断是哪个版本</p><p>Dim Info As Variant<br/>Private Sub Form_Load()<br/>Dim Location(11) As String, i As Integer</p><p>Info = Array(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1)<br/>Location(0) = "SOFTWARE\Autodesk\AutoCAD\R15.0\ACAD-1:804" '2002中文版<br/>Location(1) = "SOFTWARE\Autodesk\AutoCAD\R15.0\ACAD-1:409" '2002英文版<br/>Location(2) = "SOFTWARE\Autodesk\AutoCAD\R16.0\ACAD-201:804" '2004中文版<br/>Location(3) = "SOFTWARE\Autodesk\AutoCAD\R16.0\ACAD-201:409" '2004英文版<br/>Location(4) = "SOFTWARE\Autodesk\AutoCAD\R16.1\ACAD-301:804" '2005中文版<br/>Location(5) = "SOFTWARE\Autodesk\AutoCAD\R16.1\ACAD-301:409" '2005英文版<br/>Location(6) = "SOFTWARE\Autodesk\AutoCAD\R16.2\ACAD-4001:804" '2006中文版<br/>Location(7) = "SOFTWARE\Autodesk\AutoCAD\R16.2\ACAD-4001:409" '2006英文版<br/>Location(8) = "SOFTWARE\Autodesk\AutoCAD\R17.1\ACAD-6001:804" '2008中文版<br/>Location(9) = "SOFTWARE\Autodesk\AutoCAD\R17.1\ACAD-6001:409" '2008英文版<br/>Location(10) = "SOFTWARE\Autodesk\AutoCAD\R17.2\ACAD-7001:804" '2009中文版<br/>Location(11) = "SOFTWARE\Autodesk\AutoCAD\R17.2\ACAD-7001:409" '2009英文版<br/>&nbsp;&nbsp;&nbsp; For i = 0 To 11<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Info(i) = SearchCADversion(Location(i))<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Option1(i).Enabled = Info(i)(0)<br/>&nbsp;&nbsp;&nbsp; Next</p><p><br/>End Sub</p><p>'判断注册项是否存在<br/>Public Function IsSubKeyName(RootKey As Long, SubKeyName As String, Optional hKey As Long) As Boolean<br/>&nbsp;&nbsp;&nbsp; If RegOpenKey(RootKey, SubKeyName, hKey) = 0&amp; Then<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; IsSubKeyName = True<br/>&nbsp;&nbsp;&nbsp; Else<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; IsSubKeyName = False<br/>&nbsp;&nbsp;&nbsp; End If<br/>End Function<br/>Public Function SearchCADversion(Location As String)<br/>&nbsp;&nbsp;&nbsp; Dim Name As String * 255<br/>&nbsp;&nbsp;&nbsp; Dim lngTypeData As Long&nbsp; '返回注册表值的数据类型<br/>&nbsp;&nbsp;&nbsp; Dim intname As String '文件名所在的位置<br/>&nbsp;&nbsp;&nbsp; Dim Being As Boolean<br/>&nbsp;&nbsp;&nbsp; Dim result(1)<br/>&nbsp;&nbsp;&nbsp; If IsSubKeyName(HKEY_LOCAL_MACHINE, Location, hKey) Then '判断是否存在项目<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; RegQueryValueEx hKey, "AcadLocation", 0&amp;, lngTypeData, ByVal Name, Len(Name) '读到"AcadLocation"下数据<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; intname = Left(Name, InStr(Name, Chr(0)) - 1)<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; If Len(intname) = 0 Then '如果存在这个大项目,但是里面AcadLocation没有,就表示可能卸载过,也没有安装这个版本的CAD<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Being = False<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Else '即存在大项,又有程序位置,说明存在这个版本的CAD<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Being = True<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; End If<br/>&nbsp;&nbsp;&nbsp; Else '注册项不存在,表示没有这个版本的CAD<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Being = False<br/>&nbsp;&nbsp;&nbsp; End If<br/>&nbsp;&nbsp;&nbsp; result(0) = Being: result(1) = intname<br/>&nbsp;&nbsp;&nbsp;&nbsp; SearchCADversion = result<br/>End Function<br/></p>

wzj_711 发表于 2009-11-8 15:41:00

<p>VBA.NET某些时候需要这样判断版本 并得到版本号</p>

xmjiacad 发表于 2009-11-9 10:52:00

本帖最后由 作者 于 2009-11-9 11:50:01 编辑 <br /><br /> <p>非常感谢楼上各位的回答, 还是不能解决这个问题</p><p>请问home兄, “If IsSubKeyName(HKEY_LOCAL_MACHINE, Location, hKey) Then '判断是否存在项目”&nbsp; HKEY_LOCAL_MACHINE一直是空值,“Location(2) = "SOFTWARE\Autodesk\AutoCAD\R16.0\ACAD-201:804" '2004中文版”&nbsp;&nbsp;&nbsp;&nbsp; 这个路径到底是什么啊?是自动找路径吗?我查找了一下 没有这个。</p><p>迷茫中。。。。。。。。。</p>

home 发表于 2009-11-9 15:21:00

这是cad在注册表中的注册路径,每个版本在注册表中都有不同的名称,这样是每个版面都检索一下,来判断安装了哪个版本。

gulong2001 发表于 2009-11-9 18:59:00

三楼的只摘录了一部分,详细的见<a href="http://hi.baidu.com/kakanimo/blog/item/22f6fed2185887d8a9ec9ac8.html">http://hi.baidu.com/kakanimo/blog/item/22f6fed2185887d8a9ec9ac8.html</a>

zzyong00 发表于 2009-11-9 20:57:00

<p>读取注册表的最快的了,用createobject和getobject比较慢</p>

xmjiacad 发表于 2009-11-9 20:58:00

<p>非常感谢各位的解答,这个问题终于解决了,还有楼上给出的那个博客很不错,里面很多文章都非常受用,</p>谢谢了
页: [1]
查看完整版本: 求助:VB调用CAD时,如何读注册表检测是否安装CAD?