见上面代码。先根据搜索出来的CAD版本加上相应版本字符串得到CAD在注册表中“支持文件搜索路径”的完整位置,然后temp = GetKeyValue(HKEY_CURRENT_USER, LocationEx(i), hKey) 得到里面的值。然后用AddSupportPathtoString判断并写入,以下是上面代码中用到得函数:
Private Function GetKeyValue(RootKey As Long, SubKeyName As String, Optional hKey As Long) As String
Dim intname As String '读取的字符串
Dim Name As String * 1024 '这里要非常注意,后面这个1024如果设置小的画会下面读不出值
Dim lngTypeData As Long '返回注册表值的数据类型
Call RegOpenKey(RootKey, SubKeyName, hKey) '打开
Call RegQueryValueEx(hKey, "ACAD", 0&, lngTypeData, ByVal Name, Len(Name)) '读到"ACAD"下数据
intname = Left(Name, InStr(Name, Chr(0)) - 1)
GetKeyValue = intname
'MsgBox intname
End Function
'***********************************
'设置支持路径,
'****************************************
'入口:1.文件夹路径。2.ACAD支持路径在注册表中的位置
Function AddSupportPathtoString(ByVal Path As String, AcadFiles As String) As Boolean
Dim curSupportPath As Variant
Dim i As Integer
Dim Support As Boolean
Support = False
curSupportPath = VBA.Split(AcadFiles, ";")
For i = 0 To UBound(curSupportPath)
If StrConv(curSupportPath(i), vbUpperCase) = StrConv(Path, vbUpperCase) Then '已经存在就不添加