代码没有经过调试直接复制的桌子公司的原帖,主要是为了搜索方便
-
- using Microsoft.Win32;
- using System.Reflection;
- using Autodesk..Runtime;
- using Autodesk.AutoCAD.ApplicationServices;
- [CommandMethod("RegisterMyApp")]
- public void RegisterMyApp()
- {
- // Get the AutoCAD Applications key
- string sProdKey = HostApplicationServices.Current.RegistryProductRootKey;
- string sAppName = "MyApp";
- RegistryKey regAcadProdKey = Registry.CurrentUser.OpenSubKey(sProdKey);
- RegistryKey regAcadAppKey = regAcadProdKey.OpenSubKey("Applications", true);
- // Check to see if the "MyApp" key exists
- string[] subKeys = regAcadAppKey.GetSubKeyNames();
- foreach (string subKey in subKeys)
- {
- // If the application is already registered, exit
- if (subKey.Equals(sAppName))
- {
- regAcadAppKey.Close();
- return;
- }
- }
- // Get the location of this module
- string sAssemblyPath = Assembly.GetExecutingAssembly().Location;
- // Register the application
- RegistryKey regAppAddInKey = regAcadAppKey.CreateSubKey(sAppName);
- regAppAddInKey.SetValue("DESCRIPTION", sAppName, RegistryValueKind.String);
- regAppAddInKey.SetValue("LOADCTRLS", 14, RegistryValueKind.DWord);
- regAppAddInKey.SetValue("LOADER", sAssemblyPath, RegistryValueKind.String);
- regAppAddInKey.SetValue("MANAGED", 1, RegistryValueKind.DWord);
- regAcadAppKey.Close();
- }
- [CommandMethod("UnregisterMyApp")]
- public void UnregisterMyApp()
- {
- // Get the AutoCAD Applications key
- string sProdKey = HostApplicationServices.Current.RegistryProductRootKey;
- string sAppName = "MyApp";
- RegistryKey regAcadProdKey = Registry.CurrentUser.OpenSubKey(sProdKey);
- RegistryKey regAcadAppKey = regAcadProdKey.OpenSubKey("Applications", true);
- // Delete the key for the application
- regAcadAppKey.DeleteSubKeyTree(sAppName);
- regAcadAppKey.Close();
本帖以下内容被隐藏保护;需要你回复后,才能看到! 游客,如果您要查看本帖隐藏内容请 回复 |