472,338 Members | 1,720 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

Registry Key Permissions

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?
Nov 21 '05 #1
4 8902
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.AllAcc ess,
strHKLMPath)
fp.Assert()
' Do your read/write here
fp.RevertAssert()
fp = Nothing

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

Dim fp As New RegistryPermission(RegistryPermissionAccess.AllAcc ess,
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
Nov 21 '05 #2
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.


"Crouchie1998" <cr**********@spamcop.net> wrote in message
news:OO*************@TK2MSFTNGP12.phx.gbl...
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.AllAcc ess,
strHKLMPath)
fp.Assert()
' Do your read/write here
fp.RevertAssert()
fp = Nothing

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

Dim fp As New
RegistryPermission(RegistryPermissionAccess.AllAcc ess,
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

Nov 21 '05 #3
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
Nov 21 '05 #4
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

"Crouchie1998" <cr**********@spamcop.net> wrote in message
news:un**************@TK2MSFTNGP15.phx.gbl...
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

Nov 21 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: DJP | last post by:
Hi there I need to be able to programmatically set permissions on registry keys using VB / VBScript / VBA. So far I have had a look at doing this...
1
by: Daniel Passwater via DotNetMonster.com | last post by:
I'm working on a app that displays according to a registry key value. The user needs the ability to update the display, and hense the registry key...
21
by: Kevin Swanson | last post by:
I'm attempting some remote registry manipulation via C#. I've written a test app to simply grab a specified key from a specified hive on a specified...
3
by: Dmitriy Kolesnik | last post by:
Hello all! I have problem with reading data from registry. I work on the one machine. My operation system is Windows XP SP2. I read data from...
1
by: Kevin Burton | last post by:
I am using aspnet_setreg but the permissions that it sets the registry to leave the application unable to access the information. I want to add the...
8
by: Al Kaufman | last post by:
I have a simple console app that uses: regSubKey = <some registry key> Dim reg As RegistryKey = Registry.ClassesRoot.OpenSubKey(regSubKey) Dim...
1
by: PiotrKolodziej | last post by:
Hi Here is the code: this.regPath = @"Software\FileManager\" ; System.Security.Permissions.RegistryPermission permissions = new...
3
by: Sreppohcdoow | last post by:
I have a simple tool that I create that stores some settings in the Registry... however, if the user running it doesn't have Admin priveleges on...
0
by: tmsprowl | last post by:
Greetings! I was wondering if someone could help me with a problem I'm having. My department is just one of many within my organization. My...
0
by: concettolabs | last post by:
In today's business world, businesses are increasingly turning to PowerApps to develop custom business applications. PowerApps is a powerful tool...
0
by: CD Tom | last post by:
This only shows up in access runtime. When a user select a report from my report menu when they close the report they get a menu I've called Add-ins...
0
jalbright99669
by: jalbright99669 | last post by:
Am having a bit of a time with URL Rewrite. I need to incorporate http to https redirect with a reverse proxy. I have the URL Rewrite rules made...
0
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was...
0
by: Matthew3360 | last post by:
Hi there. I have been struggling to find out how to use a variable as my location in my header redirect function. Here is my code. ...
2
by: Matthew3360 | last post by:
Hi, I have a python app that i want to be able to get variables from a php page on my webserver. My python app is on my computer. How would I make it...
0
by: AndyPSV | last post by:
HOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and on my computerHOW CAN I CREATE AN AI with an .executable...
0
by: Arjunsri | last post by:
I have a Redshift database that I need to use as an import data source. I have configured the DSN connection using the server, port, database, and...
0
hi
by: WisdomUfot | last post by:
It's an interesting question you've got about how Gmail hides the HTTP referrer when a link in an email is clicked. While I don't have the specific...

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.