示例#1
0
 /// <summary>
 /// 通过添加注册表的方式让AutoCAD自动加载DlL
 /// </summary>
 /// <param name="appPath">Applications注册表路径</param>
 /// <param name="subKeyName">注册表子菜单名</param>
 /// <param name="desc">文件描述</param>
 /// <param name="dllPath">DLL程序路径</param>
 private static void AutoCADAutoLoadDLL(string appPath, string subKeyName, string desc, string dllPath)
 {
     Autodesk.AutoCAD.Runtime.RegistryKey locaIMachine = Autodesk.AutoCAD.Runtime.Registry.LocalMachine;
     Autodesk.AutoCAD.Runtime.RegistryKey applications = locaIMachine.OpenSubKey(appPath, true);
     Autodesk.AutoCAD.Runtime.RegistryKey myPrograrm   = applications.CreateSubKey(subKeyName);
     myPrograrm.SetValue("DESCRIPTION", desc, RegistryValueKind.String);
     myPrograrm.SetValue("LOADCTRLS", 14, RegistryValueKind.DWord);
     myPrograrm.SetValue("LOADER", dllPath, RegistryValueKind.String);
     myPrograrm.SetValue("MANAGED", 1, RegistryValueKind.DWord);
 }
示例#2
0
        // Helper functions

        private static void CreateDemandLoadingEntries(
            string name,
            string path,
            List <string> globCmds,
            List <string> locCmds,
            List <string> groups,
            int flags,
            bool currentUser
            )
        {
            // Choose a Registry hive based on the function input

            RegistryKey hive = (currentUser ? Registry.CurrentUser : Registry.LocalMachine);

            // Open the main AutoCAD (or vertical) and "Applications" keys
            //RegistryKey ack = hive.OpenSubKey(HostApplicationServices.Current.RegistryProductRootKey, true);
            RegistryKey ack = hive.OpenSubKey(HostApplicationServices.Current.UserRegistryProductRootKey, true);

            using (ack)
            {
                RegistryKey appk = ack.CreateSubKey("Applications");
                using (appk)
                {
                    // Already registered? Just return

                    string[] subKeys = appk.GetSubKeyNames();
                    foreach (string subKey in subKeys)
                    {
                        if (subKey.Equals(name))
                        {
                            return;
                        }
                    }

                    // Create the our application's root key and its values

                    RegistryKey rk = appk.CreateSubKey(name);
                    using (rk)
                    {
                        rk.SetValue(
                            "DESCRIPTION", name, RegistryValueKind.String
                            );
                        rk.SetValue("LOADCTRLS", flags, RegistryValueKind.DWord);
                        rk.SetValue("LOADER", path, RegistryValueKind.String);
                        rk.SetValue("MANAGED", 1, RegistryValueKind.DWord);

                        // Create a subkey if there are any commands...

                        if ((globCmds.Count == locCmds.Count) &&
                            globCmds.Count > 0)
                        {
                            RegistryKey ck = rk.CreateSubKey("Commands");
                            using (ck)
                            {
                                for (int i = 0; i < globCmds.Count; i++)
                                {
                                    ck.SetValue(
                                        globCmds[i],
                                        locCmds[i],
                                        RegistryValueKind.String
                                        );
                                }
                            }
                        }

                        // And the command groups, if there are any

                        if (groups.Count > 0)
                        {
                            RegistryKey gk = rk.CreateSubKey("Groups");
                            using (gk)
                            {
                                foreach (string grpName in groups)
                                {
                                    gk.SetValue(
                                        grpName, grpName, RegistryValueKind.String
                                        );
                                }
                            }
                        }
                    }
                }
            }
        }