By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,963 Members | 1,825 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,963 IT Pros & Developers. It's quick & easy.

Registry on Vista again

P: n/a
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
Feb 13 '07 #1
Share this Question
Share on Google+
6 Replies


P: n/a
Where is your logfile written?
"vovan" <so*****@vovan.comwrote in message
news:O3**************@TK2MSFTNGP02.phx.gbl...
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
Feb 13 '07 #2

P: n/a
In the same directory as service exe located - c:\MyServices
I think the problem not with log file, becase it's accessible, that
procedure writes to it.
I think this line produces an error:
val2 = pRegKey.GetValue("CSSLQ")

By some reason when it's running from Windows Service app it doesn't work.
From Windows Form project no problem with it.
One more thing - I tried to run Windows Form sample as a regular user
(double click) and it works. Now I decided to try to run it via right
click - run as Administrator. It doesn't work, producing the same error.
So it looks like Service app running with admin previlidges and that code is
not allowed.
Maybe stupid idea, but I think now I need to find the way to lower
previlidges for my service.

Thank you
Vovan

"Stuart" <no@thanks.comwrote in message
news:66**********************************@microsof t.com...
Where is your logfile written?
"vovan" <so*****@vovan.comwrote in message
news:O3**************@TK2MSFTNGP02.phx.gbl...
>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

Feb 13 '07 #3

P: n/a
sorry bud, VB 2005 on vista is yet ANOTHER visual fred moment

MS FUCKED YOU ALL GROW A BACKBONE OR DIE LIKE A PUSSY

On Feb 13, 8:40 am, "vovan" <some...@vovan.comwrote:
In the same directory as service exe located - c:\MyServices
I think the problem not with log file, becase it's accessible, that
procedure writes to it.
I think this line produces an error:
val2 = pRegKey.GetValue("CSSLQ")

By some reason when it's running from Windows Service app it doesn't work.
From Windows Form project no problem with it.
One more thing - I tried to run Windows Form sample as a regular user
(double click) and it works. Now I decided to try to run it via right
click - run as Administrator. It doesn't work, producing the same error.
So it looks like Service app running with admin previlidges and that code is
not allowed.
Maybe stupid idea, but I think now I need to find the way to lower
previlidges for my service.

Thank you
Vovan

"Stuart" <n...@thanks.comwrote in message

news:66**********************************@microsof t.com...
Where is your logfile written?
"vovan" <some...@vovan.comwrote in message
news:O3**************@TK2MSFTNGP02.phx.gbl...
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- Hide quoted text -

- Show quoted text -

Feb 14 '07 #4

P: n/a
The problem is related to Vista Registry Virtualization.
Regular Windows program running under regular user credentials let's say
need to read from "HKEY_LOCAL_MACHINE\SOFTWARE\SRS Enterprises\Coordinator"
In reality during the installation this hive was not created. Instead of it
there is a new location in HKEY_USERS.
But Windows program can see that new location and read from it.
Windows Service will still look for "HKEY_LOCAL_MACHINE\SOFTWARE\SRS
Enterprises\Coordinator", not for a new location.
So, temporarily I added manually values into HKEY_USERS. And now my service
works under Vista

Vovan

"vovan" <so*****@vovan.comwrote in message
news:O3**************@TK2MSFTNGP02.phx.gbl...
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

Feb 14 '07 #5

P: n/a
Thanks for letting us know how you got it to work.

Robin S>
------------------------------
"vovan" <so*****@vovan.comwrote in message
news:uE*************@TK2MSFTNGP05.phx.gbl...
The problem is related to Vista Registry Virtualization.
Regular Windows program running under regular user credentials let's say
need to read from "HKEY_LOCAL_MACHINE\SOFTWARE\SRS
Enterprises\Coordinator"
In reality during the installation this hive was not created. Instead of
it there is a new location in HKEY_USERS.
But Windows program can see that new location and read from it.
Windows Service will still look for "HKEY_LOCAL_MACHINE\SOFTWARE\SRS
Enterprises\Coordinator", not for a new location.
So, temporarily I added manually values into HKEY_USERS. And now my
service works under Vista

Vovan

"vovan" <so*****@vovan.comwrote in message
news:O3**************@TK2MSFTNGP02.phx.gbl...
>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.Rea d, _
"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.Rea d, _
"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


Feb 14 '07 #6

P: n/a
Hello,

If you are developing your application to make it work for Windows Vista
under a standard user account, you should STOP writing to HKLM and instead
write to HKCU directly.

This will solve both problems - the program not running correctly as
administrator, and the service failing.

In the next version of Windows, virtualization will probably not be there -
so your application will always fail with the error you are seeing now on
the next version of windows, regardless of whether it is being ran as a
standard user or not, if you do not fix it now.
--
- JB
Microsoft MVP - Windows Shell/User

Windows Vista Support Faq
http://www.jimmah.com/vista/

Feb 18 '07 #7

This discussion thread is closed

Replies have been disabled for this discussion.