Author Topic: VBA equivalent for (vlax-product-key)?  (Read 5825 times)

0 Members and 1 Guest are viewing this topic.

FengK

  • Guest
VBA equivalent for (vlax-product-key)?
« on: April 13, 2009, 05:19:29 PM »
Is there a way using VBA to get the registry key? Thanks.

Jeff_M

  • King Gator
  • Posts: 3957
  • C3D user & customizer
Re: VBA equivalent for (vlax-product-key)?
« Reply #1 on: April 13, 2009, 06:12:41 PM »
Here ya go, Kelie.
Code: [Select]
' 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

FengK

  • Guest
Re: VBA equivalent for (vlax-product-key)?
« Reply #2 on: April 13, 2009, 06:30:57 PM »
Thanks Jeff! I didn't know about the two curver's.
« Last Edit: April 13, 2009, 06:35:44 PM by xycadd »

Jeff_M

  • King Gator
  • Posts: 3957
  • C3D user & customizer
Re: VBA equivalent for (vlax-product-key)?
« Reply #3 on: April 13, 2009, 06:39:14 PM »
Wait a minute, not so fast..... I just did a little more testing and this gets the last Version to be started. IOW, start a session of 2009 and it returns the correct version. Start a session of 2008 while 2009 is running and the CurVer returns 2008 until another session of 2009 is started. Switching between sessions does not update the CurVer, nor does closing the 2008 session. The (vlax-product-key) does recognize the change.

Maybe someone has a better idea if this could cause problems.

Spike Wilbury

  • Guest
Re: VBA equivalent for (vlax-product-key)?
« Reply #4 on: April 13, 2009, 07:58:12 PM »
I just did a quick ATL/ARX project...

Maybe if you know how to use COM in VBA, you might want to try this ARX (if it is useful, I can change it to Release and uploaded again).

Since I do not know much about VBA here it is the explanation using visual lisp, after loading for register the COM server:

Quote
(setq prog-id "TheSwampCOM.CTheSwamp.1")
(setq instance (vlax-create-object prog-id))

(vlax-invoke-method instance 'ProductKey 'path)

$ path
"Software\\Autodesk\\AutoCAD\\R17.0\\ACAD-5001:409"

I just added the access to acrxProductKey(); function - it is the same as vlax-product-key in visual lisp

Jeff_M

  • King Gator
  • Posts: 3957
  • C3D user & customizer
Re: VBA equivalent for (vlax-product-key)?
« Reply #5 on: April 13, 2009, 08:21:02 PM »
Thanks Luis! This works:
Code: [Select]
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
« Last Edit: April 13, 2009, 08:25:37 PM by Jeff_M »

Spike Wilbury

  • Guest
Re: VBA equivalent for (vlax-product-key)?
« Reply #6 on: April 13, 2009, 08:27:02 PM »
Thanks Luis! This works:
Code: [Select]
Sub ARXTest()
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

End Sub

That's good, Jeff.

:)

Spike Wilbury

  • Guest
Re: VBA equivalent for (vlax-product-key)?
« Reply #7 on: April 13, 2009, 08:38:49 PM »
And it does not need to be loaded the arx anymore - give it a try and see if works.

Spike Wilbury

  • Guest
Re: VBA equivalent for (vlax-product-key)?
« Reply #8 on: April 13, 2009, 10:15:57 PM »
and in case you want to avoid COM (and if this function is not available from C# and also you want it to use this language), you can use something like:

Code: [Select]
[DllImport("acdb17.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Unicode, EntryPoint = "?acrxProductKey@@YAPB_WXZ")]
static extern string ProductKey();

[CommandMethod("GetRegPath")]
public void regPathVerCurrentlyLoaded()
{
    string path = ProductKey();
    Document doc = acadApp.DocumentManager.MdiActiveDocument;
    Editor ed = doc.Editor;
    ed.WriteMessage(path);
}

Quote
Command: netload
Command: getregpath
Software\Autodesk\AutoCAD\R17.0\ACAD-5001:409

HTH
« Last Edit: April 13, 2009, 10:20:01 PM by Luis »

Matt__W

  • Seagull
  • Posts: 12955
  • I like my water diluted.
Re: VBA equivalent for (vlax-product-key)?
« Reply #9 on: April 14, 2009, 08:59:32 AM »
Autodesk Expert Elite
Revit Subject Matter Expert (SME)
Owner/FAA sUAS Pilot @ http://skyviz.io

Jeff_M

  • King Gator
  • Posts: 3957
  • C3D user & customizer
Re: VBA equivalent for (vlax-product-key)?
« Reply #10 on: April 14, 2009, 09:35:31 AM »
Another....
That was my first thought, Matt(?), and I even saw that thread. Just I've been chastised (not here) for pushing the use of Frank's VLAX.CLS, so thought I'd attack it from a different direction. I had started to look into the ARX docs to see what I could come up with from there when Luis gave his offering.

And it does not need to be loaded the arx anymore - give it a try and see if works.
A little help here Luis. Not quite sure how I'd use something that's not loaded.....maybe it's the fact I'm at the office 2 hours earlier than normal with no coffee yet.

Spike Wilbury

  • Guest
Re: VBA equivalent for (vlax-product-key)?
« Reply #11 on: April 14, 2009, 09:52:52 AM »
And it does not need to be loaded the arx anymore - give it a try and see if works.
A little help here Luis. Not quite sure how I'd use something that's not loaded.....maybe it's the fact I'm at the office 2 hours earlier than normal with no coffee yet.

Hi Jeff,

I have done some COM apps for my own use, and I don't have to load the ARX's - I just do it the first time to register the server. :)

Jeff_M

  • King Gator
  • Posts: 3957
  • C3D user & customizer
Re: VBA equivalent for (vlax-product-key)?
« Reply #12 on: April 14, 2009, 10:04:56 AM »
I have done some COM apps for my own use, and I don't have to load the ARX's - I just do it the first time to register the server. :)
Thanks Luis. Works great!

Spike Wilbury

  • Guest
Re: VBA equivalent for (vlax-product-key)?
« Reply #13 on: April 14, 2009, 10:16:48 AM »
I have done some COM apps for my own use, and I don't have to load the ARX's - I just do it the first time to register the server. :)
Thanks Luis. Works great!

Good.


If there's some other function needed to be added in the COM, and as time permit, I might be able to help. :)

Maybe and if it is useful too, I can open a new topic in the was C++ forum and post the ATL COM project there and any member, might be able to add a new function, don't know....

Jeff_M

  • King Gator
  • Posts: 3957
  • C3D user & customizer
Re: VBA equivalent for (vlax-product-key)?
« Reply #14 on: April 14, 2009, 11:27:37 AM »
If there's some other function needed to be added in the COM, and as time permit, I might be able to help.
I think that someone started to do this once, GlennR perhaps? But having the CURVE functions available in VBA ,without the need for the Vlax.cls & curve.cls lisp converters, would be nice. But, since I have also steered away from VBA, and AutoCAD itself is, too, I'm not sure how many would find it beneficial....I know that 3-4 years ago I would've used it a lot! :-)