Windows Vista Forums
Vista Forums Home Join Vista Forums Tech Publications Windows 7 Forum Vista Tutorials Webcasts Tags

Welcome to Vista Forums we are your forum for Windows Vista help and discussion. Whether you need help or just want to post an idea you have on Vista, this is the forum for you.
Register at Vista forums...the world biggest Windows Vista resource Join Vista Forums Now

Go Back   Vista Forums > Vista Newsgroups > Vista security

Registry on Vista again

Update your Vista Drivers
Reply
 
Thread Tools Display Modes
Old 02-13-2007   #1 (permalink)
vovan
Guest


 

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



My System SpecsSystem Spec
Old 02-13-2007   #2 (permalink)
Stuart
Guest


 

Re: Registry on Vista again

Where is your logfile written?


"vovan" <someone@vovan.com> wrote in message
news:O3GkGX4THHA.2212@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
>


My System SpecsSystem Spec
Old 02-13-2007   #3 (permalink)
vovan
Guest


 

Re: Registry on Vista again

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.com> wrote in message
news:66B5CD6F-C76D-4AEB-9DBF-DE1D927EDA90@microsoft.com...
> Where is your logfile written?
>
>
> "vovan" <someone@vovan.com> wrote in message
> news:O3GkGX4THHA.2212@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
>>

>



My System SpecsSystem Spec
Old 02-14-2007   #4 (permalink)
vovan
Guest


 

Re: Registry on Vista again

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" <someone@vovan.com> wrote in message
news:O3GkGX4THHA.2212@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
>



My System SpecsSystem Spec
Old 02-14-2007   #5 (permalink)
RobinS
Guest


 

Re: Registry on Vista again

Thanks for letting us know how you got it to work.

Robin S>
------------------------------
"vovan" <someone@vovan.com> wrote in message
news:uE1peyFUHHA.920@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" <someone@vovan.com> wrote in message
> news:O3GkGX4THHA.2212@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
>>

>
>



My System SpecsSystem Spec
Old 02-17-2007   #6 (permalink)
Jimmy Brush
Guest


 

Re: Registry on Vista again

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/

My System SpecsSystem Spec
Reply
Update your Vista Drivers

Thread Tools
Display Modes



Similar Threads
Thread Thread Starter Forum Replies Last Post
Vista Registry Zygy Vista General 17 05-10-2008 03:07 AM
Registry Semi-Disaster: I am an idiot - used 2 registry 'cleaners' Sascha Jazbec Vista General 5 02-18-2008 01:01 PM
Vista registry bob Vista General 4 02-16-2008 02:13 AM
RE: vista registry BirgerH Vista account administration 0 02-14-2008 11:55 AM
Vista Registry shattered00 General Discussion 1 11-01-2007 09:16 PM


Complimentary Industry Resources

Vista Forums has joined forces with TradePub.com to offer you a new, exciting, and entirely free professional resource. Visit http://vistax64.tradepub.com today to browse our selection of complimentary Industry magazines, white papers, webinars, podcasts, and more across 34 industry sectors. No credit cards, coupons, or promo codes required. Try it today!




Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media 2005-2008

1 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 42 43 44 45 46 47 48 49 50 51