Using VB6, it took a lot of code to read values from the Registration Database. Well, not anymore with with VB.NET! Take a look at the code below.
Imports Microsoft.Win32
Function GetDBConnect() As String
Dim pobjRegKey As RegistryKey
Dim pstrValue As String
pobjRegKey = _
Registry.LocalMachine.OpenSubKey("SYSTEM\CurrentControlSet\Services\MyService\Parameters", False)
If Not IsNothing(pobjRegKey) Then
pstrValue = pobjRegKey.GetValue("DBConnect", vbNullString).ToString
Return pstrValue
Else
Return vbNullString
End If
End Function
That’s all there is to it! Basically two lines of code! This function gets a a value called “DBConnect” (database connection string) out of the Registry for a Windows Service.
Tip By: David McCarter
Discover more from dotNetTips.com
Subscribe to get the latest posts sent to your email.
