Registry Permissions

Please support our VB.NET advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Mar 2008
Posts: 324
Reputation: sonia sardana has a little shameless behaviour in the past 
Solved Threads: 7
sonia sardana sonia sardana is offline Offline
Posting Whiz

Registry Permissions

 
0
  #1
Jan 21st, 2009
Error is coming Registry Access is not allowed.While Opening a Key.
Can Somebody help me out.
  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
Reply With Quote Quick reply to this message  
Join Date: Aug 2006
Posts: 2,065
Reputation: Ramy Mahrous is just really nice Ramy Mahrous is just really nice Ramy Mahrous is just really nice Ramy Mahrous is just really nice 
Solved Threads: 256
Featured Poster
Ramy Mahrous's Avatar
Ramy Mahrous Ramy Mahrous is offline Offline
Postaholic

Re: Registry Permissions

 
0
  #2
Jan 21st, 2009
Running on Vista?
BI Developer | LINKdotNET
B.Sc Computer Science, Helwan University
Technical blog | http://ramymahrous.wordpress.com
LinkedIn | http://www.linkedin.com/in/ramymahrous
Reply With Quote Quick reply to this message  
Join Date: Mar 2008
Posts: 324
Reputation: sonia sardana has a little shameless behaviour in the past 
Solved Threads: 7
sonia sardana sonia sardana is offline Offline
Posting Whiz

Re: Registry Permissions

 
-1
  #3
Jan 23rd, 2009
  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
Reply With Quote Quick reply to this message  
Join Date: Dec 2004
Posts: 2,413
Reputation: Comatose is a jewel in the rough Comatose is a jewel in the rough Comatose is a jewel in the rough Comatose is a jewel in the rough 
Solved Threads: 211
Team Colleague
Comatose's Avatar
Comatose Comatose is offline Offline
Taboo Programmer

Re: Registry Permissions

 
0
  #4
Jan 23rd, 2009
wtf is that? That doesn't answer his question.....
Reply With Quote Quick reply to this message  
Join Date: Aug 2006
Posts: 2,065
Reputation: Ramy Mahrous is just really nice Ramy Mahrous is just really nice Ramy Mahrous is just really nice Ramy Mahrous is just really nice 
Solved Threads: 256
Featured Poster
Ramy Mahrous's Avatar
Ramy Mahrous Ramy Mahrous is offline Offline
Postaholic

Re: Registry Permissions

 
0
  #5
Jan 25th, 2009
To run as administrator
BI Developer | LINKdotNET
B.Sc Computer Science, Helwan University
Technical blog | http://ramymahrous.wordpress.com
LinkedIn | http://www.linkedin.com/in/ramymahrous
Reply With Quote Quick reply to this message  
Join Date: Dec 2004
Posts: 2,413
Reputation: Comatose is a jewel in the rough Comatose is a jewel in the rough Comatose is a jewel in the rough Comatose is a jewel in the rough 
Solved Threads: 211
Team Colleague
Comatose's Avatar
Comatose Comatose is offline Offline
Taboo Programmer

Re: Registry Permissions

 
0
  #6
Jan 25th, 2009
No No, you asked if it was vista, and they posted code....what is that about?
Reply With Quote Quick reply to this message  
Join Date: Aug 2006
Posts: 2,065
Reputation: Ramy Mahrous is just really nice Ramy Mahrous is just really nice Ramy Mahrous is just really nice Ramy Mahrous is just really nice 
Solved Threads: 256
Featured Poster
Ramy Mahrous's Avatar
Ramy Mahrous Ramy Mahrous is offline Offline
Postaholic

Re: Registry Permissions

 
0
  #7
Jan 25th, 2009
LOL, I got it, I don't know, they may understand my question wrong
BI Developer | LINKdotNET
B.Sc Computer Science, Helwan University
Technical blog | http://ramymahrous.wordpress.com
LinkedIn | http://www.linkedin.com/in/ramymahrous
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the VB.NET Forum


Views: 1006 | Replies: 6
Thread Tools Search this Thread



Tag cloud for VB.NET
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC