VBA等价物(vlax产品密钥)?
有没有使用VBA获取注册表项的方法?谢谢给你,凯莉
' Returns the AutoCAD Product Key
''''''''''''''''''''''''''''''''''''''''''''''''''''
Private Function VBA_Acad_Product_Key() As String
On Error Resume Next
' Code suggested by Tony Zanzillo & Autodesk as posted by Laurie Comerford.
' Note that the code posted in 2005 does not appear to work in the 2009 products, edited to work
' in 2009 and also to output similar results as the Lisp function (vla-product-key) by Jeff Mishler
Dim oReg As Object
Dim sVer1 As String
Dim sVer2 As String
Dim sver3 As String
Dim sProduct As String
Set oReg = CreateObject("WScript.Shell")
sVer1 = oReg.RegRead("HKEY_CURRENT_USER\SOFTWARE\Autodesk\Autocad\curver")
sVer2 = oReg.RegRead("HKEY_CURRENT_USER\SOFTWARE\Autodesk\Autocad\" & sVer1 & "\curver")
'sver3 = "HKEY_LOCAL_MACHINE\SOFTWARE\Autodesk\Autocad\" & sVer1 & "\" & sVer2 & "\ProductName"
' ' As well as product name, there are a whole series of other aspects of AutoCAD which can be recovered with this code
'' In 2009 the 2 CurVer keys are found under Current_User NOT Local_Machine as was posted. However, the Key "ProductName" IS in HKLM.
''sProduct = oReg.RegRead(sver3)
''Edited to return the key instead of the Product Name.
sver3 = "SOFTWARE\Autodesk\Autocad\" & sVer1 & "\" & sVer2
sProduct = sver3
Set oReg = Nothing
If Err0 Or sProduct = "" Then
Err.Clear
GoTo CantFindAutoCAD
End If
VBA_Acad_Product_Key = sProduct
Exit Function
CantFindAutoCAD:
sProduct = "Unable to find AutoCAD in the computer registry." & vbCrLf
MsgBox sProduct, vbCritical
End Function ' VBA_Acad_Product_Key
谢谢杰夫!我没有';我不知道两个弯道#039;s 等一下,不要那么快……我只是做了更多的测试,这就开始了最后一个版本。现在,开始2009年的一个会话,它会返回正确的版本。在2009年跑步时开始2008年的一段时间,弯曲者返回2008年,直到2009年的另一段时间开始。在会话之间切换不会更新CurVer,也不会关闭2008会话。(vlax产品密钥)确实能够识别更改
如果这会引起问题,也许有人会有更好的主意。 我刚刚做了一个快速的ATL/ARX项目…
如果你知道如何在VBA中使用COM,你可能想试试这个ARX(如果它有用,我可以将其更改为Release并再次上传)
由于我对VBA了解不多,这里是使用visual lisp进行的解释,在加载注册COM服务器后:
我刚刚添加了对acrxProductKey()的访问;函数-与visual lisp中的vlax产品密钥相同 谢谢你,路易斯!这是有效的:
Function ProductKey() As String
Dim oCom As Object
Dim progID As String
progID = "TheSwampCOM.CTheSwamp.1"
Application.LoadArx "TheSwampCOM.arx"
Set oCom = Application.GetInterfaceObject(progID)
Dim path As String
oCom.ProductKey path
Application.UnloadArx "TheSwampCOM.arx"
ProductKey = path
End Function
Sub arxtest()
Debug.Print ProductKey
End Sub
039;很好,杰夫
而且它不需要再加载arx了——试试看是否有效。 如果你想避免使用COM(如果这个函数在C中不可用,并且你也希望它使用这种语言),你可以使用类似这样的东西:
static extern string ProductKey();
public void regPathVerCurrentlyLoaded()
{
string path = ProductKey();
Document doc = acadApp.DocumentManager.MdiActiveDocument;
Editor ed = doc.Editor;
ed.WriteMessage(path);
}
HTH 另一个
页:
[1]
2