1024programmer Asp.Net CAD secondary development, write registry in the installer

CAD secondary development, write registry in the installer

CAD secondary development, write registry in the installer

1. Write registry when loading dll

We know that the dll is loaded into cad and used

HostApplicationServices.Current.RegistryProductRootKey()

You can get the current cad registry, so if you want to write when installing the program, there is no cad environment at this time, what should you do?

Second, get the registry path of all installed cad

After cad is installed, it will store the registry locations of all installed cad in the Computer\HKEY_LOCAL_MACHINE\SOFTWARE\Autodesk\Hardcopy directory of the registry

As shown in the picture, since I only installed one, only one is displayed here, and we can get all valueName values ​​by using the code

public static List GetHardcopyList()
     {
         List list = new List();
         var key = Registry.LocalMachine.CreateSubKey(@"SOFTWARE\Autodesk\Hardcopy");
         if (key != null)
         {
             string[] subKeyNames = key. GetValueNames();
             subKeyNames.Count().Prompt();
             foreach (string name in subKeyNames)
             {
                 list. Add(name);
             }
         }
         return list;
     }

After getting the valueName value, we can use the following method to write the registration form

public static void WriteZcb()
     {
         var names = GetHardcopyList();
         var dllFile = "D:\\123.dll";
         foreach (var name in names)
         {
             var address = "SOFTWARE\\" + name + "\\Applications";
             RegisteringCAD(address, dllFile);
         }
     }
     /// 
     /// Register dll
     /// 
     /// dll file path
     /// 
     public static bool RegisteringCAD(string address, string dllFile)
     {
         RegistryKey user = Registry. CurrentUser. OpenSubKey(address, true);
         if (user == null)
         {
             return false;
         }
         RegistryKey keyUserApp = user.CreateSubKey(Path.GetFileNameWithoutExtension(dllFile));
         keyUserApp.SetValue("DESCRIPTION", Path.GetFileNameWithoutExtension(dllFile), RegistryValueKind.String);
         keyUserApp.SetValue("LOADCTRLS", 2, RegistryValueKind.DWord);
         keyUserApp.SetValue("LOADER", dllFile, RegistryValueKind.String);
         keyUserApp.SetValue("MANAGED", 1, RegistryValueKind.DWord);

         return true;
     }

where dllFile is the dll path to be written

This article is from the internet and does not represent1024programmerPosition, please indicate the source when reprinting:https://www.1024programmer.com/cad-secondary-development-write-registry-in-the-installer/

author: admin

Previous article
Next article

Leave a Reply

Your email address will not be published. Required fields are marked *

Contact Us

Contact us

181-3619-1160

Online consultation: QQ交谈

E-mail: [email protected]

Working hours: Monday to Friday, 9:00-17:30, holidays off

Follow wechat
Scan wechat and follow us

Scan wechat and follow us

Follow Weibo
Back to top
首页
微信
电话
搜索