- 积分
- 2250
- 明经币
- 个
- 注册时间
- 2009-5-15
- 在线时间
- 小时
- 威望
-
- 金钱
- 个
- 贡献
-
- 激情
-
|
发表于 2015-8-10 11:08:36
|
显示全部楼层
''' <summary>
''' 让程序随CAD自动启动
''' </summary>
''' <remarks></remarks>
Public Sub RegisterMyApp()
'获得 AutoCAD 应用程序注册表键
Dim sProdKey As String = HostApplicationServices.Current.RegistryProductRootKey
'Dim sAppName As String = "MyApp"
Dim sAppName As String = My.Application.Info.AssemblyName
Dim regAcadProdKey As RegistryKey = Registry.CurrentUser.OpenSubKey(sProdKey)
Dim regAcadAppKey As RegistryKey = regAcadProdKey.OpenSubKey("Applications", True)
'检查“MyApp”键是否存在
Dim subKeys() As String = regAcadAppKey.GetSubKeyNames()
For Each sSubKey As String In subKeys
'' 如果已经存在就退出 If the application is already registered, exit
If (sSubKey.Equals(sAppName)) Then
'删除已经添加
UnregisterMyApp()
'MsgBox("已经添加了!", MsgBoxStyle.Exclamation, "提示")
'regAcadAppKey.Close()
'Exit Sub
End If
Next
'' 获得模块的位置 Get the location of this module
Dim sAssemblyPath As String = Assembly.GetExecutingAssembly().Location
'' 注册应用程序 Register the application
Dim regAppAddInKey As RegistryKey = 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()
End Sub
''' <summary>
''' 删除程序自启动
''' </summary>
''' <remarks></remarks>
Public Sub UnregisterMyApp()
'' 获得 AutoCAD 应用程序注册表键Get the AutoCAD Applications key
Dim sProdKey As String = HostApplicationServices.Current.RegistryProductRootKey
'Dim sAppName As String = "MyApp"
Dim sAppName As String = My.Application.Info.AssemblyName
Dim regAcadProdKey As RegistryKey = Registry.CurrentUser.OpenSubKey(sProdKey)
Dim regAcadAppKey As RegistryKey = regAcadProdKey.OpenSubKey("Applications", True)
'' 删除应用程序键 Delete the key for the application
Try
regAcadAppKey.DeleteSubKeyTree(sAppName)
Catch ex As Exception
MsgBox("已经取消了!", MsgBoxStyle.Exclamation, "提示")
End Try
regAcadAppKey.Close()
End Sub |
|