Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / VB.NET / June 2005

Tip: Looking for answers? Try searching our database.

Registry Key Permissions

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Kevin L - 27 Jun 2005 20:21 GMT
I store some application settings in the registry under
HKEY_LOCAL_MACHINE\Software\MyApplication

I want to allow full access to this key and subkeys.

Currently, I manually change the permissions on the keys.

How can I accomplish this through code?
Crouchie1998 - 27 Jun 2005 21:01 GMT
Hi Kevin!

Import:
-------

Imports System.Security.Permissions

Declarations:
-------------

   Dim strHKLMPath As String = "HKEY_LOCAL_MACHINE\Software\MyApplication"
   Dim strHKCUPath As String = "HKEY_CURRENT_USER\Software\MyApplication"

Example 1:
----------

       Dim fp As New RegistryPermission(RegistryPermissionAccess.AllAccess,
strHKLMPath)
       fp.Assert()
       ' Do your read/write here
       fp.RevertAssert()
       fp = Nothing

Example 2:
----------

       Dim fp As New RegistryPermission(RegistryPermissionAccess.AllAccess,
strHKLMPath)
       fp.AddPathList(RegistryPermissionAccess.AllAccess, strHKCUPath)
       fp.Assert()
       ' Do your read/write here
       fp.RevertAssert()
       fp = Nothing

Be carefull using full access as its open to abuse

I hope this helps

Crouchie1998
BA (HONS) MCP MCSE
Kevin L - 30 Jun 2005 13:59 GMT
Hi Crouchie,
I tried this but the key doesn't look all that different to me.

I did not perform the revert assuming that the change that this makes would
be undone if I "reverted".

I store application settings in the LOCAL_MACHINE\Software area. When a user
installs my application using the ADMIN account, the registry key is not
present yet (I plan on adding the key during installation, but have not
figured that out yet).

When the application is run, it is run by a non-admin account. So I need
non-admin accounts to be able to READ and WRITE values to this particular
key using my application's "settings" form. Any changes made to this key
affects all users of my application by design (hence why I put it in the
HKEY_LOCAL_MACHINE area).

Ideally, I want to create this key and assign default values at installation
time and also give full access to the key so any user can change the values
using my application's interface.

> Hi Kevin!
>
[quoted text clipped - 38 lines]
> Crouchie1998
> BA (HONS) MCP MCSE
Crouchie1998 - 30 Jun 2005 14:31 GMT
Hi Kevin,

Aha

What you need to do is when you create your setup program... you have the
registry editor in there. Create the keys you want with the registry editor
& then they will be crated on installation, as you want.

Whwn you use registry permissions like I posted before on a non-admin
account the you 'should' by rights have the appropriate permissions. If not,
use 'DEMAND', but not all circumstances will give you access rights with
that & there is no 'Revert Demand' either. So, I am not sure how you would
go about revoking registry permissions unless you destroy the object.

I have written many programs that access the registry & I have never had a
single user not being able to have the keys created/manipulated. Maybe,
there is something wrong in your code & that is why you are having problems.

Awaiting your reply,

Crouchie1998
BA (HONS) MCP MCSE
Kevin L - 30 Jun 2005 15:14 GMT
My applications typically run in a Citrix/Terminal Services environment.

I have installed applications in the past and have run into problems with
regular users not being able to retrieve my application's settings because
they did not have adequate permissions to the registry key.

I have never created the keys during installation. Perhaps the permissions
are different when creating the keys during installation using the Registry
Editor in Visual Studio?

I have always created and manipulated keys using the following code:

Sub ReadRegistry(ByVal ParentKey As RegistryKey, ByVal SubKey As String, _

ByVal ValueName As String, ByRef Value As Object)

Dim Key As RegistryKey

Try

'Open the registry key.

Key = ParentKey.OpenSubKey(SubKey, True)

If Key Is Nothing Then 'if the key doesn't exist

'Throw New Exception("The registry key doesn't exist")

End If

'Get the value.

Value = Key.GetValue(ValueName)

Console.WriteLine("Value:{0} for {1} is successfully retrieved.", Value,
ValueName)

Catch e As Exception

Console.WriteLine("Error occurs in ReadRegistry" & e.Message)

End Try

End Sub

Sub WriteRegistry(ByVal ParentKey As RegistryKey, ByVal SubKey As String, _

ByVal ValueName As String, ByVal Value As Object)

Dim Key As RegistryKey

Try

'Open the registry key.

Key = ParentKey.OpenSubKey(SubKey, True)

If Key Is Nothing Then 'if the key doesn't exist.

Key = ParentKey.CreateSubKey(SubKey)

End If

'Set the value.

Key.SetValue(ValueName, Value)

Console.WriteLine("Value:{0} for {1} is successfully written.", Value,
ValueName)

Catch e As Exception

Console.WriteLine("Error occurs in WriteRegistry" & e.Message)

End Try

End Sub

> Hi Kevin,
>
[quoted text clipped - 21 lines]
> Crouchie1998
> BA (HONS) MCP MCSE

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.