| 1 |
#Region "Microsoft.VisualBasic::edc000362f4d5dfd9be253745cf13508, Microsoft.VisualBasic.Core\ApplicationServices\VBDev\Ngen\Registry.vb"
|
| 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 |
#End Region
|
| 42 |
|
| 43 |
Imports System.Reflection
|
| 44 |
Imports System.Runtime.InteropServices
|
| 45 |
Imports Microsoft.VisualBasic.CommandLine.Reflection
|
| 46 |
Imports Microsoft.VisualBasic.Scripting.MetaData
|
| 47 |
Imports Microsoft.Win32
|
| 48 |
|
| 49 |
Namespace ApplicationServices
|
| 50 |
|
| 51 |
Public Module RegistryUtils
|
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
<ExportAPI("RegAsm")>
|
| 60 |
Public Function RegisterCOMDll(<Parameter("COM.Dll", "The file path of the DLL file which will be registered as a COM component.")> COM_Dll As String) As Boolean
|
| 61 |
Dim Asm As Assembly = Assembly.LoadFile(COM_Dll)
|
| 62 |
Dim regAsm As New RegistrationServices
|
| 63 |
Dim bResult As Boolean = regAsm.RegisterAssembly(Asm, AssemblyRegistrationFlags.SetCodeBase)
|
| 64 |
Return bResult
|
| 65 |
End Function
|
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
> https://msdn.microsoft.com/en-us/library/ee722096.aspx
|
| 71 |
|
| 72 |
<param name="PATH$"></param>
|
| 73 |
Public Function RegisterExtensions(PATH$, company$) As String
|
| 74 |
Try
|
| 75 |
Call WriteToRegistry(RegistryHive.LocalMachine, $"SOFTWARE\Microsoft\.NETFramework\v4.0.30319\AssemblyFoldersEx\{company}\", "", PATH)
|
| 76 |
Catch ex As Exception
|
| 77 |
Return ex.ToString
|
| 78 |
End Try
|
| 79 |
|
| 80 |
Return "success!"
|
| 81 |
End Function
|
| 82 |
|
| 83 |
Public Function WriteToRegistry(ParentKeyHive As RegistryHive, SubKeyName$, ValueName$, Value As Object) As Boolean
|
| 84 |
|
| 85 |
|
| 86 |
|
| 87 |
' bAns = WriteToRegistry(RegistryHive.LocalMachine, "SOFTWARE\MyCompany\MyProgram\", "ProgramHasRunBefore", "Y")
|
| 88 |
' Debug.WriteLine("Registry Write Successful: " & bAns)
|
| 89 |
|
| 90 |
Dim objSubKey As RegistryKey
|
| 91 |
Dim sException$ = Nothing
|
| 92 |
Dim objParentKey As RegistryKey
|
| 93 |
Dim bAns As Boolean
|
| 94 |
|
| 95 |
Select Case ParentKeyHive
|
| 96 |
Case RegistryHive.ClassesRoot
|
| 97 |
objParentKey = Registry.ClassesRoot
|
| 98 |
Case RegistryHive.CurrentConfig
|
| 99 |
objParentKey = Registry.CurrentConfig
|
| 100 |
Case RegistryHive.CurrentUser
|
| 101 |
objParentKey = Registry.CurrentUser
|
| 102 |
Case RegistryHive.DynData
|
| 103 |
#Disable Warning
|
| 104 |
objParentKey = Registry.DynData
|
| 105 |
#Enable Warning
|
| 106 |
Case RegistryHive.LocalMachine
|
| 107 |
objParentKey = Registry.LocalMachine
|
| 108 |
Case RegistryHive.PerformanceData
|
| 109 |
objParentKey = Registry.PerformanceData
|
| 110 |
Case RegistryHive.Users
|
| 111 |
objParentKey = Registry.Users
|
| 112 |
Case Else
|
| 113 |
Throw New Exception(ParentKeyHive.ToString)
|
| 114 |
End Select
|
| 115 |
|
| 116 |
|
| 117 |
objSubKey = objParentKey.OpenSubKey(SubKeyName, True)
|
| 118 |
|
| 119 |
|
| 120 |
If objSubKey Is Nothing Then
|
| 121 |
objSubKey = objParentKey.CreateSubKey(SubKeyName)
|
| 122 |
End If
|
| 123 |
|
| 124 |
objSubKey.SetValue(ValueName, Value)
|
| 125 |
bAns = True
|
| 126 |
|
| 127 |
Return bAns
|
| 128 |
End Function
|
| 129 |
End Module
|
| 130 |
End Namespace
|