PDA

View Full Version : Modifying the registry with VBA



jpaulsen
2004-10-04, 08:42 PM
I would like to start by saying I know very little about VBA.

I am trying to update a program written for AutoCAD (LDT) 2002 for use in AutoCAD (LDT) 2005.

The program does several things; modifies the Autoexec.bat, modifies the sdsk.dfm file, modifies the acad.pgp and modifies the registry.

The code to modify the registry works in 2005 as it did in 2002. However, I am having trouble trying to edit some additional keys that were not being edited previously. I also want to know how to make a new key and then delete a key. I will explain the specifics below.

Modify a registry key

The following code modifies the Support File Search Path:

Set acadPref = ThisDrawing.Application.Preferences.Files
acadPref.SupportPath = "Z:\Land Desktop 2005\JRSupport;Z:\etc.

The registry key that holds this value is:

HKEY_CURRENT_USER\Software\Autodesk\AutoCAD\R16.1\ACAD-308:409\Profiles\Land Desktop 2005\General\ACAD

How does SupportPath (program) relate to ACAD (registry key)?

Is there a list of “program keys” (for lack of the correct term) and the corresponding registry keys?

In particular I want to set the following:

§ acadPref.SheetSetTemplatePath = "Z:\Land Desktop 2005\JRTemplate"
§ acadPref.QnewTemplate = "Z:\Land Desktop 2005\JRTemplate\_jr settings.dwt"
§ acadPref.AlternativePageSetUpsTemplate = "Z:\Land Desktop 2005\JRTemplate\_jr settings.dwt"
§ acadPref.ToolPalettePath = "Z:\Land Desktop 2005\JRToolPalette;U:\Land Desktop 2005\Tool Palette"
§ acadPref.DefaultConfig = "Z:\Land Desktop 2005\Plotters\zAutodesk\PublishToWeb JPG.pc3"

These are listed with the registry key names as they appear in the registry. Coincidentally the ToolPalettePath line works but the other four return the following error:

Run-time error ‘438’: Object doesn’t support this property or method

Add a registry key

After doing some experimenting, it appears that the solution to my problem above answers this question. When I deleted the key;


HKEY_CURRENT_USER\Software\Autodesk\AutoCAD\R16.1\ACAD-308:409\Profiles\Land Desktop 2005\General\ACAD

It is re-created when I run the program. So I guess all I need to know is the proper “program key”.

The keys that I want to add are:

§ HKEY_CURRENT_USER\Software\Autodesk\AutoCAD\R16.1\ACAD-308:409\Profiles\Land Desktop\General Configuration\ModeBits (Full time CRC validation)
§ HKEY_CURRENT_USER\Software\Autodesk\AutoCAD\R16.1\ACAD-308:409\Profiles\Land Desktop\General\HideSystemPrinters

Note: The full time CRC key is in General Configuration, not General. All the other keys listed in this post are under General. I am not sure how that path relates to acadPref.

Delete a registry key

At a later date I may decide to turn off Full time CRC validation. How would I delete the corresponding registry key?

Thanks in advance to anyone who took the time to read my very long post.

inner69923
2004-10-05, 12:21 AM
this work in vb, maybe in vba, if not just make a dll and call it from vba

Ed Jobe
2004-10-05, 04:51 PM
All of these items can be handled via a saved profile, you don't need to set them programattically. They also shouldn't change often. Its best to use acad to set them instead of the registry, however, if you still want to, you need to learn the acad object model. These are properties of various preferences objects. These correspond to the different tabs in the Options dialog. You could find more info by using the Object Browser (F2) in the vbaide. The first ones are properties of the AcadPreferencesFiles object. The ToolPalettePath is the only valid property. I don't know where you came up with the others. The path that stores the templates is TemplateDwgPath. There is no default config property, the dwg stores the layout's settings. You should be using named page setups for this. In the object model, they are called PlotConfigurations. I have a dvb on the Exchange that you can use for this.

If LDT is anything like ADT, then what you call SheetSetTemplatePath and AlternativePageSetUpsTemplate should be in the project file, which is xml.

The crc prop is under AcadPreferencesOpenSave.FullCRCValidation. Unfortunately, there is no property for the option to hide system printers. For that, you would have to directly edit the registry.