一、加载dll时写注册表
我们知道,dll加载到cad中后使用- HostApplicationServices.Current.RegistryProductRootKey()
复制代码 就可以拿到当前cad的注册表,那么如果想在安装程序时写,此时并没有cad的环境,要怎么办呢?
二、获取所有已安装的cad的注册表路径
cad在安装后,会在注册表的计算机\HKEY_LOCAL_MACHINE\SOFTWARE\Autodesk\Hardcopy目录下存放所有已安装的cad的注册表位置

如图,由于我只安装了一个,所以这里只显示一个,我们使用代码即可获取到所有的valueName值- public static List<string> GetHardcopyList()
- {
- List<string> list = new List<string>();
- 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;
- }
复制代码
拿到valueName值后,我们可以用如下方法写上注册表- 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);
- }
- }
- /// <summary>
- /// 注册dll
- /// </summary>
- /// <param name="dllFile">dll文件路径</param>
- /// <returns></returns>
- 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;
- }
复制代码 其中 dllFile为要写入的dll路径
免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作! |