473,624 Members | 2,426 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to get the registry key permission using RegistryRight in NET2.0?

yxq
Hello,
I want to get the registry key permission information whether current user
has the permission to delete the registry key using RegistryRights, how to
do? thank you.


Dec 9 '06 #1
4 3223
Public Sub AccessRegistry( ByVal rk As RegistryKey, ByVal sKey As
String, ByVal action As RegistryPermiss ionAccess)
Dim rp As New RegistryPermiss ion(PermissionS tate.None)
rp.SetPathList( action, rk.Name)
rp.Demand()

Select Case action
Case RegistryPermiss ionAccess.Creat e
rk.CreateSubKey ("Third Sector Technologies")
Case RegistryPermiss ionAccess.Read
Dim sk As RegistryKey = rk.OpenSubKey(s Key)
Dim sValue As String = sk.GetValue("Fl oyd")
Case RegistryPermiss ionAccess.Write
Dim sk As RegistryKey = rk.OpenSubKey(s Key)
sk.SetValue("Fl oyd", 1)
End Select
End Sub

Call this code like this:

Dim rk As RegistryKey = Registry.Curren tUser
AccessRegistry( rk, "Third Sector Technologies",
RegistryPermiss ionAccess.Creat e)
"yxq" <ga***@163.netw rote in message
news:eF******** *****@TK2MSFTNG P02.phx.gbl...
Hello,
I want to get the registry key permission information whether current user
has the permission to delete the registry key using RegistryRights, how to
do? thank you.


Dec 11 '06 #2
Also

Function RegistryRetriev e(parent As RegistryKey, keyName As String,
valueName As String) As String
' Recursively search through each subkey of a parent key
' checking to see if a match for the keyname exist and if
' the data can be obtained from that key. Returns data
upon
' match and an error message otherwise.
Dim childName As String
For Each childName In parent.GetSubKe yNames()
Try
Dim child As RegistryKey =
parent.OpenSubK ey(childName)
Dim data As String = Nothing
If child.Name.Ends With(keyName) Then
' We found the name, try to pull out key
data
data = child.GetValue( valueName)
Else
' No luck finding the name, try a
depth-first recursive search
data = RegistryRetriev e(child, keyName,
valueName)
End If
If Not (data Is Nothing) Then
Return data
End If
Catch ex As Exception
' Print out a message whenever we come
across a
' key we don't have permissions to open
Console.WriteLi ne((childName + ": " +
ex.Message))
End Try
Next childName
Return Nothing
End Function

"yxq" <ga***@163.netw rote in message
news:eF******** *****@TK2MSFTNG P02.phx.gbl...
Hello,
I want to get the registry key permission information whether current user
has the permission to delete the registry key using RegistryRights, how to
do? thank you.


Dec 11 '06 #3
yxq
Thank you.

"vbnetdev" <ad***@kjmsolut ions.comдÈëÏûÏ ¢ÐÂÎÅ:%2******* *********@TK2MS FTNGP02.phx.gbl ...
Also

Function RegistryRetriev e(parent As RegistryKey, keyName As String,
valueName As String) As String
' Recursively search through each subkey of a parent key
' checking to see if a match for the keyname exist and
if
' the data can be obtained from that key. Returns data
upon
' match and an error message otherwise.
Dim childName As String
For Each childName In parent.GetSubKe yNames()
Try
Dim child As RegistryKey =
parent.OpenSubK ey(childName)
Dim data As String = Nothing
If child.Name.Ends With(keyName) Then
' We found the name, try to pull out
key data
data = child.GetValue( valueName)
Else
' No luck finding the name, try a
depth-first recursive search
data = RegistryRetriev e(child, keyName,
valueName)
End If
If Not (data Is Nothing) Then
Return data
End If
Catch ex As Exception
' Print out a message whenever we come
across a
' key we don't have permissions to open
Console.WriteLi ne((childName + ": " +
ex.Message))
End Try
Next childName
Return Nothing
End Function

"yxq" <ga***@163.netw rote in message
news:eF******** *****@TK2MSFTNG P02.phx.gbl...
>Hello,
I want to get the registry key permission information whether current
user has the permission to delete the registry key using RegistryRights,
how to do? thank you.




Dec 11 '06 #4
yxq
Thank you, how to remove and add the write permission of current user for
Registry key?

"vbnetdev" <ad***@kjmsolut ions.comдÈëÏûÏ ¢ÐÂÎÅ:u2******* ******@TK2MSFTN GP06.phx.gbl...
Public Sub AccessRegistry( ByVal rk As RegistryKey, ByVal sKey As
String, ByVal action As RegistryPermiss ionAccess)
Dim rp As New RegistryPermiss ion(PermissionS tate.None)
rp.SetPathList( action, rk.Name)
rp.Demand()

Select Case action
Case RegistryPermiss ionAccess.Creat e
rk.CreateSubKey ("Third Sector Technologies")
Case RegistryPermiss ionAccess.Read
Dim sk As RegistryKey = rk.OpenSubKey(s Key)
Dim sValue As String = sk.GetValue("Fl oyd")
Case RegistryPermiss ionAccess.Write
Dim sk As RegistryKey = rk.OpenSubKey(s Key)
sk.SetValue("Fl oyd", 1)
End Select
End Sub

Call this code like this:

Dim rk As RegistryKey = Registry.Curren tUser
AccessRegistry( rk, "Third Sector Technologies",
RegistryPermiss ionAccess.Creat e)
"yxq" <ga***@163.netw rote in message
news:eF******** *****@TK2MSFTNG P02.phx.gbl...
>Hello,
I want to get the registry key permission information whether current
user has the permission to delete the registry key using RegistryRights,
how to do? thank you.



Dec 11 '06 #5

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

Similar topics

7
14824
by: Bob | last post by:
I'm working on a Windows app that needs to write to the Registry HKLM. I keep getting a "System.UnauthorizedAccessException: Cannot write to the registry key." error when running the app. I'm logged in as an Administrator and it's a Windows app. What permission does it need? Here's the code. private void ChangeReg() { string regPath = "SOFTWARE\\Microsoft\\.NETFramework\\AssemblyFolders"; RegistryKey thisKey = Registry.LocalMachine;
2
4149
by: Andrew | last post by:
I spent tons of time searching the web for how to use .NET 2.0 and C# to modify Registry key security. After finally finding an example, and once I knew the function names a few other small examples.. I can still find nothing that demonstrates how to take ownership of a Registry key if one has (potentially) *only* "write owner" The problem, of course is that normally, to read or change permissions, one needs to "open" the registry key to...
9
7207
by: Andrew | last post by:
Apologies for the double-post.. I'm new, just getting used to this.. and should have posted this way in the first place.. How does one go about taking ownership of a registry key using C# & .NET 2.0 *IF* one has _only_ TakeOwnership privilege? The problem is exactly as specified in MS KB Article ID: 111546 at: http://support.microsoft.com/kb/111546/EN-US/ ...except that I would like to know how to do it in C#
11
3572
by: Josh Flanagan | last post by:
I am trying to write to the event log from ASP.NET, on Windows XP SP1. As soon as I try to write an event (or even query the source with EventLog.SourceExists() or EventLog.LogNameFromSourceName()) I get a SecurityException "Requested registry access is not allowed.". I have read the KB article associated with this error message, which indicates the source needs to be created outside of ASP.NET. I created an Installer class, and ran...
2
3240
by: Sachin | last post by:
Hi All, I am using aspnet_setreg.exe to encrypt the username and password and store them in Web.Config file for impersonation. I have given ASPNET and Impersonation account to read the registry key. However, while running the application it fails saying that can't read the password for Registrty.
8
5482
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(""))
0
938
by: Filippo Bettinaglio | last post by:
PermView.exe - .NET Framework Permission Request Viewer. Why PermView.exe is not included any more in the .NET2 Framework? Is there a correspondent utility for .net2 assemblies? Many Thanks, Filippo
0
3998
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...
6
3682
tlhintoq
by: tlhintoq | last post by:
I pride myself on being able to Google just about anything but... I have fought, tried, searched and fought some more on this one. I am using VMware, and am able to debug from Visual Studio to the VMware virtual machine... Right up until the application being debugged tries to write to the registry. Then it fails due to lack of security permissions. It writes to the Host PC registry just fine. This is only happening when remote...
0
8240
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8175
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
8680
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...
1
8336
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
8482
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...
0
7168
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
4177
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2610
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
1
1791
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.