473,834 Members | 1,874 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Registry Key Permissions

I store some application settings in the registry under
HKEY_LOCAL_MACH INE\Software\My Application

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 9123
Hi Kevin!

Import:
-------

Imports System.Security .Permissions

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

Dim strHKLMPath As String = "HKEY_LOCAL_MAC HINE\Software\M yApplication"
Dim strHKCUPath As String = "HKEY_CURRENT_U SER\Software\My Application"

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

Dim fp As New RegistryPermiss ion(RegistryPer missionAccess.A llAccess,
strHKLMPath)
fp.Assert()
' Do your read/write here
fp.RevertAssert ()
fp = Nothing

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

Dim fp As New RegistryPermiss ion(RegistryPer missionAccess.A llAccess,
strHKLMPath)
fp.AddPathList( RegistryPermiss ionAccess.AllAc cess, 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\S oftware 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_MACH INE 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.


"Crouchie19 98" <cr**********@s pamcop.net> wrote in message
news:OO******** *****@TK2MSFTNG P12.phx.gbl...
Hi Kevin!

Import:
-------

Imports System.Security .Permissions

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

Dim strHKLMPath As String = "HKEY_LOCAL_MAC HINE\Software\M yApplication"
Dim strHKCUPath As String = "HKEY_CURRENT_U SER\Software\My Application"

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

Dim fp As New
RegistryPermiss ion(RegistryPer missionAccess.A llAccess,
strHKLMPath)
fp.Assert()
' Do your read/write here
fp.RevertAssert ()
fp = Nothing

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

Dim fp As New
RegistryPermiss ion(RegistryPer missionAccess.A llAccess,
strHKLMPath)
fp.AddPathList( RegistryPermiss ionAccess.AllAc cess, 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(By Val 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.OpenS ubKey(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(Va lueName)

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

Catch e As Exception

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

End Try

End Sub

Sub WriteRegistry(B yVal 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.OpenS ubKey(SubKey, True)

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

Key = ParentKey.Creat eSubKey(SubKey)

End If

'Set the value.

Key.SetValue(Va lueName, Value)

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

Catch e As Exception

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

End Try

End Sub

"Crouchie19 98" <cr**********@s pamcop.net> wrote in message
news:un******** ******@TK2MSFTN GP15.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
7698
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 using the WScript.Shell object, API calls, and WMI but the only one of these that goes any where near registry permissions is WMI and that is only to get the permissions of a key (cannot set). I am also quite happy for the code to call an external program to perform the task but can't seem to...
1
3073
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 (via a click event on a popup menu). This all worked just fine until some users were set up as power-users. I've tried to change the permissions on that key programatically, on the fly, but to no avail. Here's my question: While the user is logged in with limited permissions, will the...
21
10840
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 machine. The call to OpenSubKey is throwing System.SecurityException. Also of note: Sitting at my local box, I can open regedit and connect to the remote registry. I see three hives: _CLASSES_ROOT, _LOCAL_MACHINE, and _USERS. I can open all but HKEY_LOCAL_MACHINE. When I try to expand that...
3
3269
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 registry with help OpenSubKey and SecurityException appeares for key HKEY_CURRENT_USER\Software\Microsoft\Protected Storage System provider\S-1-5-21-2025815041-1961764723-2087665911-3808. I saw permissions in this key - permissions for SYSTEM exist only. How I can read this key
1
2100
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 ASPNET account on the machine that our application is being installed on with read privilege automatically. Does anyone know of a way to easily set registry permissions? I would prefer to use .NET (C#) but I can always wrap any code that does this. I am suspecting that this will involve C++ or...
8
5497
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 path As String path = CStr(reg.GetValue(""))
1
6581
by: PiotrKolodziej | last post by:
Hi Here is the code: this.regPath = @"Software\FileManager\" ; System.Security.Permissions.RegistryPermission permissions = new System.Security.Permissions.RegistryPermission(System.Security.Permissions.RegistryPermissionAccess.AllAccess, @"HKEY_LOCAL_MACHINE\" + regPath);
3
2287
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 the machine, the app fails when trying to write to the registry. I know there are applications out there that can read/write to the registry w/o Admin priveleges... is there some way to code around this in C#.NET? I.e., to have the program run the registry code in a different security context...
0
4010
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 organization has control over the network domain, but my department has a couple of web servers of our own that are part of my organization's domain. I am trying to read LDAP information on my organization's domain controller from a web application on one of my department's servers. I have been...
0
9646
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10793
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10510
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10548
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10219
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7758
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5794
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4427
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
3081
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.