-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathInstaller.vb
150 lines (85 loc) · 3.54 KB
/
Installer.vb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
Imports Microsoft.Win32
Imports System.Reflection
Imports System.Runtime.InteropServices
Imports System.Runtime.Remoting.Contexts
<ComVisible(False)>
<ClassInterface(ClassInterfaceType.None)>
Public Class Installer
Public ASSEMBLY_TYPE As Type
Public ASSEMBLY_GUID As String
Public ASSEMBLY_FLAG As Integer
Public ASSEMBLY_NAME As Assembly
Public ASSEMBLY_KEYNAME As String
Public ASSEMBLY_DISPLAY_NAME As String
Public REGISTRATION_SERVICES As RegistrationServices
Public Sub New()
MyBase.New()
InitializeComponent() 'This call is required by the Component Designer.
'Add initialization code after the call to InitializeComponent
ASSEMBLY_TYPE = GetType(Functions)
ASSEMBLY_GUID = Functions.ClassId.ToUpper
ASSEMBLY_NAME = GetType(Functions).Assembly
ASSEMBLY_FLAG = AssemblyRegistrationFlags.SetCodeBase
ASSEMBLY_KEYNAME = "CLSID\{" & ASSEMBLY_GUID & "}\"
ASSEMBLY_DISPLAY_NAME = ASSEMBLY_NAME.FullName
REGISTRATION_SERVICES = New RegistrationServices
End Sub
Public Overrides Sub Install(stateSaver As IDictionary)
MyBase.Install(stateSaver)
REGISTER_ASSEMBLY()
UPDATE_REGISTRY_KEYS()
End Sub
Public Overrides Sub Commit(savedState As IDictionary)
MyBase.Commit(savedState)
End Sub
Public Overrides Sub Rollback(savedState As IDictionary)
MyBase.Rollback(savedState)
End Sub
Public Overrides Sub Uninstall(savedState As IDictionary)
MyBase.Uninstall(savedState)
REMOVE_REGISTRY_KEY()
UNREGISTER_ASSEMBLY()
End Sub
Public Sub REGISTER_ASSEMBLY()
Try
REGISTRATION_SERVICES.RegisterAssembly(ASSEMBLY_NAME, ASSEMBLY_FLAG)
Catch ex As Exception
INSTALL_ERROR("Error Registering Assembly", ex.Message)
End Try
End Sub
Public Sub UPDATE_REGISTRY_KEYS()
Dim SetKey As RegistryKey = Nothing
Try
Registry.ClassesRoot.CreateSubKey(ASSEMBLY_KEYNAME & "Programmable")
SetKey = Registry.ClassesRoot.OpenSubKey(ASSEMBLY_KEYNAME & "InprocServer32", True)
SetKey.SetValue("", Environment.SystemDirectory & "\mscoree.dll", RegistryValueKind.String)
Registry.ClassesRoot.Close()
Catch ex As Exception
INSTALL_ERROR("Error updating registry", ex.Message, "Registry Key = " & SetKey.ToString)
End Try
End Sub
Public Sub REMOVE_REGISTRY_KEY()
Try
Registry.ClassesRoot.DeleteSubKey(ASSEMBLY_KEYNAME & "Programmable")
Registry.ClassesRoot.Flush()
Catch ex As Exception
INSTALL_ERROR("Error deleting subkey", ex.Message, "Registry SubKey = " & ASSEMBLY_KEYNAME & "Programmable")
End Try
End Sub
Public Sub UNREGISTER_ASSEMBLY()
Try
REGISTRATION_SERVICES.UnregisterAssembly(ASSEMBLY_NAME)
Catch ex As Exception
INSTALL_ERROR("Error UnRegistering Assembly", ex.Message)
End Try
End Sub
Public Sub INSTALL_ERROR(BOX_TITLE As String, MESSAGE As String, Optional EXTRA_TEXT As String = "")
Dim NEWLINE As String = vbCrLf & vbCrLf
Dim BOXTEXT As String = NEWLINE
BOXTEXT &= "Assembly Name = " & ASSEMBLY_DISPLAY_NAME & NEWLINE
BOXTEXT &= "Assembly GUID = " & ASSEMBLY_GUID & NEWLINE
BOXTEXT &= "Message = " & MESSAGE & NEWLINE
BOXTEXT &= EXTRA_TEXT
MsgBox(BOXTEXT, vbCritical + vbOKOnly, " " & BOX_TITLE)
End Sub
End Class