943,892 Members | Top Members by Rank

Ad:
  • VB.NET Discussion Thread
  • Unsolved
  • Views: 1889
  • VB.NET RSS
Jan 21st, 2009
0

Registry Permissions

Expand Post »
Error is coming Registry Access is not allowed.While Opening a Key.
Can Somebody help me out.
VB.NET Syntax (Toggle Plain Text)
  1. Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
  2. NewDelete("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Run", "Sonia")
  3. End Sub
  4.  
  5. Private Sub NewDelete(ByVal KeyPath As String, ByVal KeyName As String)
  6. Dim sMainKey As String
  7. Dim sKeyPath As String
  8. Dim ObjReg As RegistryKey
  9. Dim sData As Object
  10.  
  11.  
  12. Try
  13.  
  14.  
  15. Dim mSec As New RegistrySecurity()
  16. Dim user As String = Environment.UserDomainName & "\" & Environment.UserName
  17.  
  18. sMainKey = Mid(KeyPath, 1, InStr(KeyPath, "\", Microsoft.VisualBasic.CompareMethod.Text) - 1)
  19. ObjReg = GetMainKey(sMainKey)
  20. sKeyPath = Replace(KeyPath, sMainKey, "")
  21. Do While True
  22. If Mid(sKeyPath, 1, 1) = "\" Then
  23. sKeyPath = Mid(sKeyPath, 2)
  24. Else
  25. Exit Do
  26. End If
  27. Application.DoEvents()
  28. Loop
  29.  
  30. Dim rule As New Security.AccessControl.RegistryAccessRule(user, _
  31. Security.AccessControl.RegistryRights.FullControl, _
  32. Security.AccessControl.AccessControlType.Allow)
  33.  
  34.  
  35.  
  36. mSec.AddAccessRule(New RegistryAccessRule(user, RegistryRights.FullControl, _
  37. System.Security.AccessControl.InheritanceFlags.ContainerInherit, _
  38. PropagationFlags.None, AccessControlType.Allow))
  39.  
  40.  
  41. ObjReg = ObjReg.OpenSubKey(sKeyPath, True)
  42. ObjReg.SetAccessControl(mSec)
  43. If ObjReg IsNot Nothing Then ObjReg.Close()
  44.  
  45. mSec.AddAccessRule(rule)
  46. 'if Object .Equals (
  47. If Not ObjReg Is Nothing Then
  48. sData = Registry.GetValue(ObjReg.ToString, KeyName, "")
  49. If Not sData Is "" Then
  50. ObjReg.DeleteValue(KeyName, False)
  51. End If
  52. End If
  53.  
  54. Catch ex As Exception
  55. MsgBox(ex.Message)
  56. End Try
  57. End Sub
Similar Threads
Reputation Points: 0
Solved Threads: 8
Posting Whiz
sonia sardana is offline Offline
326 posts
since Mar 2008
Jan 21st, 2009
0

Re: Registry Permissions

Running on Vista?
Featured Poster
Reputation Points: 480
Solved Threads: 276
Postaholic
Ramy Mahrous is offline Offline
2,189 posts
since Aug 2006
Jan 23rd, 2009
-1

Re: Registry Permissions

VB.NET Syntax (Toggle Plain Text)
  1. Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
  2. Dim a As RegistryPermission = New RegistryPermission( _
  3. RegistryPermissionAccess.AllAccess, "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\Sonia")
  4. a.Demand()
  5. NewDelete("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\Sonia", "ss")
  6. End Sub
  7.  
  8. Private Sub NewDelete(ByVal KeyPath As String, ByVal KeyName As String)
  9. Dim sMainKey As String
  10. Dim sKeyPath As String
  11. Dim ObjReg As RegistryKey
  12. Dim sData As Object
  13.  
  14.  
  15. Try
  16.  
  17.  
  18.  
  19.  
  20.  
  21. sMainKey = Mid(KeyPath, 1, InStr(KeyPath, "\", Microsoft.VisualBasic.CompareMethod.Text) - 1)
  22. ObjReg = Registry.LocalMachine
  23. sKeyPath = Replace(KeyPath, sMainKey, "")
  24. Do While True
  25. If Mid(sKeyPath, 1, 1) = "\" Then
  26. sKeyPath = Mid(sKeyPath, 2)
  27. Else
  28. Exit Do
  29. End If
  30. Application.DoEvents()
  31. Loop
  32.  
  33. ObjReg = ObjReg.OpenSubKey(sKeyPath, True)
  34.  
  35. If Not ObjReg Is Nothing Then
  36. sData = Registry.GetValue(ObjReg.ToString, KeyName, "")
  37. If Not sData Is "" Then
  38. ObjReg.DeleteValue(KeyName, False)
  39. End If
  40. End If
  41.  
  42. Catch ex As Exception
  43. MsgBox(ex.Message)
  44. End Try
  45. End Sub
Last edited by Ancient Dragon; Jan 23rd, 2009 at 7:03 pm. Reason: add code tags
Reputation Points: 0
Solved Threads: 8
Posting Whiz
sonia sardana is offline Offline
326 posts
since Mar 2008
Jan 23rd, 2009
0

Re: Registry Permissions

wtf is that? That doesn't answer his question.....
Team Colleague
Reputation Points: 361
Solved Threads: 214
Taboo Programmer
Comatose is offline Offline
2,413 posts
since Dec 2004
Jan 25th, 2009
0

Re: Registry Permissions

To run as administrator
Featured Poster
Reputation Points: 480
Solved Threads: 276
Postaholic
Ramy Mahrous is offline Offline
2,189 posts
since Aug 2006
Jan 25th, 2009
0

Re: Registry Permissions

No No, you asked if it was vista, and they posted code....what is that about?
Team Colleague
Reputation Points: 361
Solved Threads: 214
Taboo Programmer
Comatose is offline Offline
2,413 posts
since Dec 2004
Jan 25th, 2009
0

Re: Registry Permissions

LOL, I got it, I don't know, they may understand my question wrong
Featured Poster
Reputation Points: 480
Solved Threads: 276
Postaholic
Ramy Mahrous is offline Offline
2,189 posts
since Aug 2006

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in VB.NET Forum Timeline: Coding Problem
Next Thread in VB.NET Forum Timeline: ISBN 10/13 validation and conversion





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC