V
vovan
I'm asking for help one more time. Below are 2 procedures. The first one is
used in VB 2005 Windows Form project. It works fine on XP, Vista.
Private Sub RegistryReadingTest()
Try
Dim f As New RegistryPermission(RegistryPermissionAccess.Read, _
"HKEY_LOCAL_MACHINE\SOFTWARE\SRS
Enterprises\Coordinator\Settings")
f.Demand()
Dim pRegKey As RegistryKey = Registry.LocalMachine
pRegKey = pRegKey.OpenSubKey("SOFTWARE\SRS
Enterprises\Coordinator\Settings")
Dim val2 As Object
val2 = pRegKey.GetValue("CSSLQ")
TextBox1.Text = val2.ToString()
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
End Sub
'************************************************************************
The second procedure is used in Windows Service application. The code is the
same except I write the return value into file. This procedure does work on
XP, but returns an error 'object reference not set to an instance of an
object' on Vista Business.
What is wrong with this code. How can I make it work on Vista?
Private Sub RegistryReadingTest()
Try
Dim f As New RegistryPermission(RegistryPermissionAccess.Read, _
"HKEY_LOCAL_MACHINE\SOFTWARE\SRS
Enterprises\Coordinator\Settings")
f.Demand()
Dim pRegKey As RegistryKey = Registry.LocalMachine
pRegKey = pRegKey.OpenSubKey("SOFTWARE\SRS
Enterprises\Coordinator\Settings")
Dim val2 As Object
val2 = pRegKey.GetValue("CSSLQ")
WriteToLog("Connection String From Registry: " &
val2.ToString())
Catch ex As Exception
WriteToLog("Error: " & ex.Message())
End Try
End Sub
used in VB 2005 Windows Form project. It works fine on XP, Vista.
Private Sub RegistryReadingTest()
Try
Dim f As New RegistryPermission(RegistryPermissionAccess.Read, _
"HKEY_LOCAL_MACHINE\SOFTWARE\SRS
Enterprises\Coordinator\Settings")
f.Demand()
Dim pRegKey As RegistryKey = Registry.LocalMachine
pRegKey = pRegKey.OpenSubKey("SOFTWARE\SRS
Enterprises\Coordinator\Settings")
Dim val2 As Object
val2 = pRegKey.GetValue("CSSLQ")
TextBox1.Text = val2.ToString()
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
End Sub
'************************************************************************
The second procedure is used in Windows Service application. The code is the
same except I write the return value into file. This procedure does work on
XP, but returns an error 'object reference not set to an instance of an
object' on Vista Business.
What is wrong with this code. How can I make it work on Vista?
Private Sub RegistryReadingTest()
Try
Dim f As New RegistryPermission(RegistryPermissionAccess.Read, _
"HKEY_LOCAL_MACHINE\SOFTWARE\SRS
Enterprises\Coordinator\Settings")
f.Demand()
Dim pRegKey As RegistryKey = Registry.LocalMachine
pRegKey = pRegKey.OpenSubKey("SOFTWARE\SRS
Enterprises\Coordinator\Settings")
Dim val2 As Object
val2 = pRegKey.GetValue("CSSLQ")
WriteToLog("Connection String From Registry: " &
val2.ToString())
Catch ex As Exception
WriteToLog("Error: " & ex.Message())
End Try
End Sub