Exemplo n.º 1
0
        /// <summary>
        /// 得到电脑当前已经安装的CAD版本号
        /// </summary>
        /// <returns></returns>
        private static List <string> GetHasInstallCADVersion()
        {
            List <string> versionList = new List <string>();

            Autodesk.AutoCAD.Runtime.RegistryKey locaIMachine = Autodesk.AutoCAD.Runtime.Registry.LocalMachine;
            Autodesk.AutoCAD.Runtime.RegistryKey applications = locaIMachine.OpenSubKey("SOFTWARE\\Autodesk\\AutoCAD\\", true);
            string[] subKeys = applications.GetSubKeyNames();
            foreach (string subKey in subKeys)
            {
                string version = "";
                switch (subKey)
                {
                case "R17.1":
                    version = "2008";
                    break;

                case "R17.2":
                    version = "2009";
                    break;

                case "R18.0":
                    version = "2010";
                    break;

                case "R18.1":
                    version = "2011";
                    break;

                case "R18.2":
                    version = "2012";
                    break;

                case "R19.0":
                    version = "2013";
                    break;

                case "R19.1":
                    version = "2014";
                    break;

                case "R20.0":
                    version = "2015";
                    break;

                case "R20.1":
                    version = "2016";
                    break;

                default:
                    version = "";
                    break;
                }
                versionList.Add(version);
            }
            return(versionList);
        }
Exemplo n.º 2
0
        private static void UninstallRegedit(string appPath)
        {
            Document dwg  = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
            Editor   aced = dwg.Editor;

            aced.WriteMessage("\n 开始删除AutoCAD CMCU插件注册表:");
            try
            {
                Autodesk.AutoCAD.Runtime.RegistryKey LocalMachine = Autodesk.AutoCAD.Runtime.Registry.LocalMachine;
                Autodesk.AutoCAD.Runtime.RegistryKey Applications = LocalMachine.OpenSubKey(appPath, true);
                string[] subKeys = Applications.GetSubKeyNames();
                if (subKeys.Contains(CommonVariable.regeditSubKeyName))
                {
                    Applications.DeleteSubKeyTree(CommonVariable.regeditSubKeyName);
                }
                aced.WriteMessage("\n 删除AutoCAD CMCU插件注册表成功");
            }
            catch (System.Exception ex)
            {
                aced.WriteMessage("\n 删除AutoCAD CMCU插件注册表失败!");
                aced.WriteMessage("\n{0}", ex.ToString());
            }
        }
Exemplo n.º 3
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
                                        );
                                }
                            }
                        }
                    }
                }
            }
        }