954,517 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Registry Permissions

Error is coming Registry Access is not allowed.While Opening a Key.
Can Somebody help me out.

Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
        NewDelete("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Run", "Sonia")
    End Sub

    Private Sub NewDelete(ByVal KeyPath As String, ByVal KeyName As String)
        Dim sMainKey As String
        Dim sKeyPath As String
        Dim ObjReg As RegistryKey
        Dim sData As Object

       
        Try
           

            Dim mSec As New RegistrySecurity()
            Dim user As String = Environment.UserDomainName & "\" & Environment.UserName

            sMainKey = Mid(KeyPath, 1, InStr(KeyPath, "\", Microsoft.VisualBasic.CompareMethod.Text) - 1)
            ObjReg = GetMainKey(sMainKey)
            sKeyPath = Replace(KeyPath, sMainKey, "")
            Do While True
                If Mid(sKeyPath, 1, 1) = "\" Then
                    sKeyPath = Mid(sKeyPath, 2)
                Else
                    Exit Do
                End If
                Application.DoEvents()
            Loop

            Dim rule As New Security.AccessControl.RegistryAccessRule(user, _
            Security.AccessControl.RegistryRights.FullControl, _
            Security.AccessControl.AccessControlType.Allow)



            mSec.AddAccessRule(New RegistryAccessRule(user, RegistryRights.FullControl, _
           System.Security.AccessControl.InheritanceFlags.ContainerInherit, _
           PropagationFlags.None, AccessControlType.Allow))


            ObjReg = ObjReg.OpenSubKey(sKeyPath, True)
            ObjReg.SetAccessControl(mSec)
            If ObjReg IsNot Nothing Then ObjReg.Close()

            mSec.AddAccessRule(rule)
            'if Object .Equals (
            If Not ObjReg Is Nothing Then
                sData = Registry.GetValue(ObjReg.ToString, KeyName, "")
                If Not sData Is "" Then
                    ObjReg.DeleteValue(KeyName, False)
                End If
            End If

        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
    End Sub
sonia sardana
Posting Whiz
326 posts since Mar 2008
Reputation Points: 0
Solved Threads: 8
 

Running on Vista?

Ramy Mahrous
Postaholic
2,196 posts since Aug 2006
Reputation Points: 480
Solved Threads: 276
 
Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
        Dim a As RegistryPermission = New RegistryPermission( _
        RegistryPermissionAccess.AllAccess, "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\Sonia")
        a.Demand()
        NewDelete("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\Sonia", "ss")
    End Sub

    Private Sub NewDelete(ByVal KeyPath As String, ByVal KeyName As String)
        Dim sMainKey As String
        Dim sKeyPath As String
        Dim ObjReg As RegistryKey
        Dim sData As Object


        Try





            sMainKey = Mid(KeyPath, 1, InStr(KeyPath, "\", Microsoft.VisualBasic.CompareMethod.Text) - 1)
            ObjReg = Registry.LocalMachine
            sKeyPath = Replace(KeyPath, sMainKey, "")
            Do While True
                If Mid(sKeyPath, 1, 1) = "\" Then
                    sKeyPath = Mid(sKeyPath, 2)
                Else
                    Exit Do
                End If
                Application.DoEvents()
            Loop

            ObjReg = ObjReg.OpenSubKey(sKeyPath, True)
           
            If Not ObjReg Is Nothing Then
                sData = Registry.GetValue(ObjReg.ToString, KeyName, "")
                If Not sData Is "" Then
                    ObjReg.DeleteValue(KeyName, False)
                End If
            End If

        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
    End Sub
sonia sardana
Posting Whiz
326 posts since Mar 2008
Reputation Points: 0
Solved Threads: 8
 

wtf is that? That doesn't answer his question.....

Comatose
Taboo Programmer
Team Colleague
2,910 posts since Dec 2004
Reputation Points: 361
Solved Threads: 215
 

To run as administrator

Ramy Mahrous
Postaholic
2,196 posts since Aug 2006
Reputation Points: 480
Solved Threads: 276
 

No No, you asked if it was vista, and they posted code....what is that about?

Comatose
Taboo Programmer
Team Colleague
2,910 posts since Dec 2004
Reputation Points: 361
Solved Threads: 215
 

LOL, I got it, I don't know, they may understand my question wrong :D

Ramy Mahrous
Postaholic
2,196 posts since Aug 2006
Reputation Points: 480
Solved Threads: 276
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You