给你,凯莉。
- ' 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 Err 0 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
|