- 积分
- 22862
- 明经币
- 个
- 注册时间
- 2016-5-25
- 在线时间
- 小时
- 威望
-
- 金钱
- 个
- 贡献
-
- 激情
-
|
代码没有经过调试直接复制的桌子公司的原帖,主要是为了搜索方便
https://forums.autodesk.com/t5/n ... regkey/td-p/6650480
- using Microsoft.Win32;
- using System.Reflection;
- using Autodesk.AutoCAD.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();
|
|