473,324 Members | 2,179 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,324 software developers and data experts.

Registry on Vista again

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
6 1620
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
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
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: BigAbility | last post by:
is there registry in Longhorn( vista) ? i heard about Registry will disappear in longhorn. is it true?
6
by: Steve Teeples | last post by:
I have a piece of code (written is Visual Studio 2005) that is only reading the Security EventLog. On Windows XP Professiona/Home this code works just fine. int numberOfEntries =...
11
by: vovan | last post by:
I'm using this approach to read from registry. Dim f As New RegistryPermission(RegistryPermissionAccess.AllAccess, _ "HKEY_LOCAL_MACHINE\SOFTWARE\SRS Enterprises\Coordinator\Settings") 'Vlad...
2
by: =?Utf-8?B?QW5qYW5h?= | last post by:
Hello we creating a web application in ASP .net 2.0. we are trying to read font file path from registry as below Microsoft.Win32.RegistryKey registryKeyParen registryKeyChild =...
3
by: Rob Latour | last post by:
The following snippet (vb.net 2005) is working just fine in xp but not in vista in xp it lists all related sub keys in the registry just fine. in vista it doesn't list certain ones (like...
2
by: =?Utf-8?B?UGV0ZQ==?= | last post by:
Hi, I have developed a VB application in VS2005 and deployed it sucessfully to XP using an MSI file built with a standard VS setup project. The MSI creates some keys under...
2
by: terryastone | last post by:
I have an application that reads some registry values stored in the Local Machine\Software\... key. In XP, I can see these values using RegEdit. In my application I can read the values at...
3
by: thephatp | last post by:
This is incredibly strange. I used regedit and went to HKEY_LOCAL_MACHINE and create a new subkey under "Software". I added a few more, then went into code to try to read them. I kept getting...
6
by: sd | last post by:
hello I need to keep my app entry under HKEY_LOCAL_MACHINE\Software\MyApp. (to support for all users).I need to update one key under MYApp. When I attempt to set value for this key...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.