Home All Groups Group Topic Archive Search About

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

Author
9 Dec 2006 3:10 PM
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.

Author
11 Dec 2006 12:23 PM
vbnetdev
Public Sub AccessRegistry(ByVal rk As RegistryKey, ByVal sKey As
    String, ByVal action As RegistryPermissionAccess)
        Dim rp As New RegistryPermission(PermissionState.None)
        rp.SetPathList(action, rk.Name)
        rp.Demand()

        Select Case action
            Case RegistryPermissionAccess.Create
                rk.CreateSubKey("Third Sector Technologies")
            Case RegistryPermissionAccess.Read
                Dim sk As RegistryKey = rk.OpenSubKey(sKey)
                Dim sValue As String = sk.GetValue("Floyd")
            Case RegistryPermissionAccess.Write
                Dim sk As RegistryKey = rk.OpenSubKey(sKey)
                sk.SetValue("Floyd", 1)
        End Select
    End Sub

Call this code like this:

    Dim rk As RegistryKey = Registry.CurrentUser
    AccessRegistry(rk, "Third Sector Technologies",
    RegistryPermissionAccess.Create)


Show quoteHide quote
"yxq" <ga***@163.net> wrote in message
news:eFZ1pQ6GHHA.924@TK2MSFTNGP02.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.
>
>
>
>
Author
11 Dec 2006 2:16 PM
yxq
Thank you, how to remove and add the write permission of current user for
Registry key?

Show quoteHide quote
"vbnetdev" <ad***@kjmsolutions.com> дÈëÏûÏ¢ÐÂÎÅ:u2E868RHHHA.***@TK2MSFTNGP06.phx.gbl...
> Public Sub AccessRegistry(ByVal rk As RegistryKey, ByVal sKey As
>    String, ByVal action As RegistryPermissionAccess)
>        Dim rp As New RegistryPermission(PermissionState.None)
>        rp.SetPathList(action, rk.Name)
>        rp.Demand()
>
>        Select Case action
>            Case RegistryPermissionAccess.Create
>                rk.CreateSubKey("Third Sector Technologies")
>            Case RegistryPermissionAccess.Read
>                Dim sk As RegistryKey = rk.OpenSubKey(sKey)
>                Dim sValue As String = sk.GetValue("Floyd")
>            Case RegistryPermissionAccess.Write
>                Dim sk As RegistryKey = rk.OpenSubKey(sKey)
>                sk.SetValue("Floyd", 1)
>        End Select
>    End Sub
>
> Call this code like this:
>
>    Dim rk As RegistryKey = Registry.CurrentUser
>    AccessRegistry(rk, "Third Sector Technologies",
>    RegistryPermissionAccess.Create)
>
>
> "yxq" <ga***@163.net> wrote in message
> news:eFZ1pQ6GHHA.924@TK2MSFTNGP02.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.
>>
>>
>>
>>
>
>
Author
11 Dec 2006 12:33 PM
vbnetdev
Also

Function RegistryRetrieve(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.GetSubKeyNames()
                              Try
                                 Dim child As RegistryKey =
parent.OpenSubKey(childName)
                                 Dim data As String = Nothing
                                 If child.Name.EndsWith(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 = RegistryRetrieve(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.WriteLine((childName + ": " +
ex.Message))
                              End Try
                   Next childName


                   Return Nothing
        End Function

Show quoteHide quote
"yxq" <ga***@163.net> wrote in message
news:eFZ1pQ6GHHA.924@TK2MSFTNGP02.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.
>
>
>
>
Author
11 Dec 2006 2:13 PM
yxq
Thank you.

Show quoteHide quote
"vbnetdev" <ad***@kjmsolutions.com> дÈëÏûÏ¢ÐÂÎÅ:%23z9vKCSHHHA.1***@TK2MSFTNGP02.phx.gbl...
> Also
>
> Function RegistryRetrieve(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.GetSubKeyNames()
>                              Try
>                                 Dim child As RegistryKey =
> parent.OpenSubKey(childName)
>                                 Dim data As String = Nothing
>                                 If child.Name.EndsWith(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 = RegistryRetrieve(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.WriteLine((childName + ": " +
> ex.Message))
>                              End Try
>                   Next childName
>
>
>                   Return Nothing
>        End Function
>
> "yxq" <ga***@163.net> wrote in message
> news:eFZ1pQ6GHHA.924@TK2MSFTNGP02.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.
>>
>>
>>
>>
>
>
>