VB.net 2010 视频教程 VB.net 2010 视频教程 python基础视频教程
SQL Server 2008 视频教程 c#入门经典教程 Visual Basic从门到精通视频教程
当前位置:
首页 > temp > C#教程 >
  • CAD二次开发,安装程序中写注册表

一、加载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路径

出处:https://www.cnblogs.com/d1742647821/p/17306914.html


相关教程